Posts Tagged ‘asp’

Using .asp and cookies to implement a MOTD

February 27th, 2007 No comments

code tagIf you want your webpage to display a message of the day (MOTD) for the first time your users access the page and not again until the next day, you can achieve this using a cookie.

Basically, it checks to see if the date stored in the cookie is before today and displays the appropriate page content. Once it has been displayed, it sets the date in the cookie to today to prevent any further display until tomorrow.

' If the date in the stored cookie is before today
< % If (Request.Cookies("CookieName")("LastVisit") < Date) Then %>

This text will only be displayed the first time the page is accessed each day

' Now the message has been displayed,
' set the date in the cookie to today's date
< % Response.Cookies("CookieName")("LastVisit") = Date end if %>

Categories: Uncategorized Tags: