Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-26-2009, 03:37 PM   #1
Fully Optimized
 
LukaszR's Avatar
 
Join Date: May 2008
Posts: 2,833
Send a message via MSN to LukaszR
Default cookies....

Hey there, i need help regarding Cookies using .ASP pages.

So what i am required to do is this, I need to be able to read the cookie and place the values from the cookie into the web page textboxes so they are displayed when the page is opened.

Here is the code i have up to now;
Quote:
<%
Response.Cookies("Log")
Response.Cookies("Log").Expires=DATE() + 5

'setup some variables
Dim UserName, Password, Address
'read a cookie file. First the User Name
UserName=Request.Cookies("UserName")
'Next the Password
Password=Request.Cookies("Password")
'Next the Address
Address=Request.Cookies("Address")






%>


<html>
<head>
<title>Accounts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<h4 align="center"><font face="Arial, Helvetica, sans-serif" size="5"><b><font color="#990000">Accounts
</font></b></font><font face="Arial, Helvetica, sans-serif"><br>
Client Accounts</font></h4>

<form method="post" action="">
<table width="96%" border="0" align="center">
<tr>
<td width="37%">User Name :</td>
<td width="63%">
<input type="text" name="txtname" size="40">

</td>
</tr>
<tr>
<td width="37%">Password:</td>
<td width="63%">
<input type="password" name="txtpassword">
</td>
</tr>
<tr>

</tr>
<tr>
<td width="37%">Address:</td>
<td width="63%">
<input type="text" name="txtaddress">
</td>
</tr>
<tr>
<td width="37%">&nbsp;</td>
<td width="63%">
<input type="submit" name="Submit" value="Save Data">

</td>
</tr>
<tr>
<td width="37%">&nbsp;</td>
<td width="63%">&nbsp;</td>
</tr>
</table>
</form>
<h4 align="center"><font size="1" face="Arial, Helvetica, sans-serif">Please show the lab assistant when completed
</body>
</html>
Now, my cookie is called "Log". How do i view the cookies content? Also, when i visit the .asp page in my web browser, and input all the fields...and choose to save the log in info...when i reload the page..its all there except for the address field. Could someone double check my coding please.

Any help would be appreciated. Thanks.
__________________

__________________
Desktop - DualBoot: Fedora 15/Windows 7 64bit
Netbook - Windows 7 Professional

www.Cyber-Talk.ca League of Legends and Gaming Community
LukaszR is offline   Reply With Quote
Old 03-26-2009, 05:01 PM   #2
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: cookies....

for the text on your input's:

<input type="text" id="uName" name="uName" width="20%"><%=Request.Cookies("Log")("uName")%></input>

where fieldName is the name of the input element.

When you create the cookie, you should add different "items" to the single cookie, instead of creating several different ones (unless you're supposed to). So for example When you are creating your cookies at the top, check to make sure a cookie hasn't been set first:
Code:
Dim uName As String = ""
uName = Request.Cookies("Log")("uName")
if uName.Length > 0 then
 ' Do nothing, we're all set here
Else
 'The cookie hasn't been set yet, so try to set the cookies value to whatever they put in the form.
  Request.Cookies("Log")("uName") = Request.Form("uName")
end if
Hope that helps.
__________________

__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 03-26-2009, 07:28 PM   #3
Fully Optimized
 
LukaszR's Avatar
 
Join Date: May 2008
Posts: 2,833
Send a message via MSN to LukaszR
Default Re: cookies....

oo...ok i think i understand what you are doing there. Thanks for your input, i will rewrite the code and test it out. I'll let you know how it goes...and whether or not i get the full marks for the lab.

Thanks again.
__________________
Desktop - DualBoot: Fedora 15/Windows 7 64bit
Netbook - Windows 7 Professional

www.Cyber-Talk.ca League of Legends and Gaming Community
LukaszR is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 11:27 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0