Retrieve Cookie in ASP
Thursday, December 13th, 2007Here is how you retrieve a cookie in ASP.
Request.Cookies("cookieName")
or
MyVariable=Request.Cookies("cookieName")
or
If Request.Cookies("cookieName")="Yes" then
Popularity: 2%
Daily Web Design Inspiration & Ideas
Here is how you retrieve a cookie in ASP.
Request.Cookies("cookieName")
or
MyVariable=Request.Cookies("cookieName")
or
If Request.Cookies("cookieName")="Yes" then
Popularity: 2%
Use the Expiration line of code if you want the cookie to last globaly throughout all the browser windows. If you do not include the Expiration line and just use the one Response.Cookie(”blownies”) - “something” line the cookie will only last in this specific window until it is closed.
‘create a 10-day cookie
Response.Cookies(”brownies”) = 13
Response.Cookies(”brownies”).Expires = Date() + 10
‘create a static date cookie
Response.Cookies(”name”) = “Suzy Q.”
Response.Cookies(”name”).Expires = #January 1,2009#
‘you can also specify domain if going from a http to https.
Response.Cookies(”brownies”).Domain = “domain.com”
Popularity: 2%
I had to quickly post this one here. I’ve been using this quick and easy, static login script on multiple ASP applications. Just copy tha code, paste it into your code, set a password and it’s ready to go. Don’t forget to change the login form action value.
<%@ Language=VBScript
Option Explicit
Dim bLogInSaved, cmd, pw””””””””””””””””””
‘ SET YOUR PASSWORED HEREpw = “password”
””””””””””””””””””
If Session(”letin”) = “allow” Then
bLogInSaved = True
else
bLogInSaved = False
End IfIf Request.Form(”password”) <> “” Then
If Request.Form(”password”) = pw Then
Session(”letin”) = “allow”
bLogInSaved = True
else
bLogInSaved = False
End If
End IfIf Request.QueryString(”logout”) = “1″ Then
Session.Contents.RemoveAll
bLogInSaved = False
End IfIf bLogInSaved Then
%>
<p> PASSWORD PROTECTED PAGE GOES HERE </p>
<%
ElseResponse.Write “<center><form name=”"login”"” & _
” method=”"post”" action=”"ThisPagesName.asp”">” & _
“<table width=”"345″” border=”"0″” cellspacing=”"0″” ” & _
“cellpadding=”"0″”><tr><td width=”"190″”>” & _
“<font size=”"2″” face=”"Arial, Helvetica, sans-serif”">” & _
“Please enter the Password:</font> </td>” & _
“<td width=”"155″”><input type=”"text”" ” & _
“name=”"password”"></td></tr></table>” & _
“</form></center>”End If
%>
Popularity: 2%
Turn the first letter of every word in a string to Upper case in ASP by using thes function. The original script is from http://www.scripts.com.
<%
finalText = format_ucase(”Every word in this string will be capitalized”)
function format_ucase(tname)
do while instr(tname, ” “)
temp_string = left(tname, instr(tname,” ” ) -1)
‘ ucase the first letter
format_ucase = format_ucase & ucase(mid(temp_string, 1,1))
‘ lcase for the rest of the word
format_ucase = format_ucase & lcase(mid(temp_string,2)) & ” “
tname = right(tname, len(tname) - instr(tname,” ” ))
loop
’send out the rest of the word
format_ucase = format_ucase & ucase(mid(tname, 1,1))
format_ucase = format_ucase & mid(tname,2)
end function
%>
Popularity: 2%
Turn your ASP string text to upper or lower case with ease by using these comands.
<%mySentense = "This text is going to be upper or lower case"
Response.Write UCASE(mySentense) 'Upper Case
Response.Write LCASE(mySentense) 'Lower Case
%>
Popularity: 2%
Here is how you send email in ASP. This will use the local server as teh mail server so just send a test email to yourself and see if it works on your server.
<%
Set objMsg = Server.CreateObject("CDONTS.NewMail")
objMsg.From = "My Name <email@domain.com>"
objMsg.To = "email@domain.com" ' who do you want to send to?
objMsg.Cc = "secondEmail@domain.com" ' who do you want to CC?
objMsg.Subject = "Subject line"
objMsg.BodyFormat = 0
objMsg.MailFormat = 0
objMsg.Body = "Email message goes here"
objMsg.Send
Set objMsg = Nothing
%>
Popularity: 2%
Want to have a dynamic message that shows only for the 4th of July? Here is how I did it:
<%
Dim fourthjul, nowmonth, nowday, fourthmon
Dim fourthday, fourthmonend, fourthdayend
nowmonth = CInt(Month(date))
nowday = CInt(Day(date))
fourthmon = CInt(5)
fourthday = CInt(25)
fourthmonend = CInt(6)
fourthdayend ? CInt(5)if nowmonth >= fourthmon and nowday >= fourthday and nowmonth <= fourthmonend and nowday <= fourthdayend then
%><p><strong class="orange">Holiday Hours</strong><br />
Our Corporate Office and Customer Service will be closed<br />
<%=WeekDayName(Weekday("06-04-" & Year(date))) %>, July 4th. We will resume normal business hours on <%=WeekDayName(Weekday("06-05-" & Year(date))) %>, July 5th.
<%
end if
%>
Popularity: 12%