Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 12 May
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Using Cookies to see if our Visitor has been Before

<% If Request.Cookies("BeenHereBefore") = "True" Then
sMessage = "You've been to this page before!"
Else
sMessage = "Hi, Hope you enjoy this page and come back again!"
Response.Cookies("BeenHereBefore") = "True"
Response.Cookies("BeenHereBefore").Expires=Now+60
End If

Response.Write(sMessage)
%>

When our visitor arrives at our page we check to see If our cookie called BeenHereBefore exists and if it has the value "True". If it does then we set the value of the sMessage variable to "You've been to this page before!". If the cookie doesn't exist and doesn't hold the value "True" then we set sMessage to "Hi, Hope you enjoy this page and come back again!". We also write the cookie BeenHereBefore to the visitors machine. Our cookie also has an attribute, in this case a date when the cookie will expire. It's 60 days from now i.e. 'Now + 60'.

If you do not set the Expires attribute then the cookie will expire when the user closes their browser.

Here's our code in practice:
Hi, Hope you enjoy this page and come back again!

If you get the message "Hi, Hope you enjoy this page and come back again!" click refresh on your browser and see what happens.

Read more on Reading and writing cookies





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software