Give a warm welcome to your visitors! - Cookie Reader Script
Have you noticed that some websites know your name when you arrive? Example: http://aguyslife.blogdrive.com Ever wondered how this is done, or wanted your own? Well here is the code and an explanation.
Copy the code directly into your html page where you want the name to appear. Where it says document.write ("Welcome " & name) replace Welcome with whatever message you want.
How does it work? The script only works on computers which have cookies enabled, and they must also have used a Blogdrive.com tagboard, or the main tagboard. However most of your blog readers will have done this.
First of all it opens the Blogdrive.com cookie into a variable named username, then it creates a variable called cookielen which contains a number equal to the number of characters in the cookie. The cookie contains several bits of information; the name is just one. The format for a cookie is stringname=value;.
In the blogdrive cookie, name is the first string. The DO loop starts at the 15th character of the cookie which is the start of the name value. It adds the 15th character to the username variable then checks for then semi colon which denotes the end of the value. If it finds a semi colon it ends the loop, and prints the name variable which contains the name of the user. Otherwise it loops and adds another letter and checks again for a semi colon etc.
By Guy Burton
Posted at 09:08 pm on Sunday, June 13, 2004 by Guyb
View Comments: 9 Permalink