Solved

Check this code

Posted on 2004-09-25
108
269 Views
Last Modified: 2008-02-01
I am trying to get a value from a check box located in a form. If it is check (value = on) then it should make a cookie that can save the email addres that is held in a dim called strUserName does it look right.

 IF request.form("C1") = "ON" then
             Response.Cookies("Email") = strUserName
             Response.Redirect"staffmainpage.asp"
             else
             Response.Redirect"staffmainpage.asp"
             end if
0
Comment
Question by:eteran
  • 50
  • 26
  • 17
  • +4
108 Comments
 
LVL 15

Assisted Solution

by:Thogek
Thogek earned 100 total points
Comment Utility
Unless you've explicitly set value="on" in your input type="checkbox" element, then the value you're looking for is "on", not "ON".  (Values are case-sensitive.)  I.e.,

    IF request.form("C1") = "on" then
0
 

Author Comment

by:eteran
Comment Utility
ON
0
 

Author Comment

by:eteran
Comment Utility
Does the rest sound fine
0
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 150 total points
Comment Utility
try to do this

Response.Write "strUserName = " & strUserName
Response.Cookies("Email") = strUserName


to print out the value of strUserName. I suspect there's no values in it.
0
 
LVL 15

Assisted Solution

by:gladxml
gladxml earned 50 total points
Comment Utility
You can try this approach...

if Request("C1").Count > 0 then  
           Response.Cookies("Email") = strUserName
           Response.Redirect"staffmainpage.asp"
           else
           Response.Redirect"staffmainpage.asp"
           end if

Happy programming...

0
 
LVL 15

Assisted Solution

by:Thogek
Thogek earned 100 total points
Comment Utility
> ON

What does this mean?
Perhaps you could just post the HTML for the checkbox element?

gladxml's approach might also work, BTW, as long as there are no other form elements with the same name.
0
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 200 total points
Comment Utility
Just wieighing in:

Give the check box a value, i.e.:

<input type="checkbox" name="C1" value="storeEmail">

Now, if you have the box checked, request.form("C1") will return "storeEmail" otherwise it will return an empty string.

So then:

if request.form("C1") = "storeEmail" then
    Response.Cookies("Email") = strUserName
end if
Response.Redirect("staffmainpage.asp")


Also, as you can see, there is no reason to have the redirect twice--regardless of the if condition, you still want the redirect.
0
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 200 total points
Comment Utility
To check your cookies, here is a handy cookie reader:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<%
dim strCookieName, strKeyName
for each strCookieName in Request.Cookies
      if request.Cookies(strCookieName).HasKeys then
            for each strKeyName in Request.Cookies(strCookieName)
                  response.write(strCookieName & "(" & strKeyName & ") = " & request.cookies(strCookieName)(strKeyName) & "<BR>")
            next
      else
            response.write(strCookieName & " = " & request.cookies(strCookieName) & "<BR>")
      end if
next
%>
</BODY>
</HTML>
0
 

Author Comment

by:eteran
Comment Utility
Where can I check to see if the cookie has been created. I have wind\ow XP
0
 

Author Comment

by:eteran
Comment Utility
Also,

Now how can I check if the cookie is there and if so I can I autopopulate the informaiton on a text box with this name "txtUserName"
0
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 200 total points
Comment Utility
To read cookies, just save that code I gave you into an .asp file and run it. It will show you all of the cookies for that domain.

FtB
0
 

Author Comment

by:eteran
Comment Utility
Nothing comes out
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
if it's there, then FtB code will read and display it
0
 

Author Comment

by:eteran
Comment Utility
            IF request.form("C1") = "ON" then
             Response.Cookies("Email") = strUserName
             end if
             Response.Redirect"staffmainpage.asp"
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
you need to allow cookies
0
 

Author Comment

by:eteran
Comment Utility
<%
'Dimension variables
Dim adoCon             'Database Connection Variable
Dim strCon            'Holds the Database driver and the path and name of the database
Dim rsCheckUser             'Database Recordset Variable
Dim strAccessDB       'Holds the Access Database Name
Dim strSQL             'Database query sring
Dim strUserName       'Holds the user name

'Initalise the strUserName variable
strUserName = Request.Form("txtUserName")
strpassword = request.form("txtUserPass")
'Check the database to see if user exsits and read in there password
'Initialise the strAccessDB variable with the name of the Access Database
strAccessDB = "ctinter"

'Create a connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
                  
'Database connection info and driver
strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=F:\hshome\cyht/cyyht.mdb"

'Set an active connection to the Connection object
adoCon.Open strCon

'Create a recordset object
Set rsCheckUser = Server.CreateObject("ADODB.Recordset")

'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM T_employees WHERE Company_Email ='" & strUserName & "' and Disable = 0"

'Query the database
rsCheckUser.Open strSQL, strCon

'If the recordset finds a record for the username entered then read in the password for the user
If NOT rsCheckUser.EOF Then
      
      'Read in the password for the user from the database
      'If (Request.Form("txtUserPass")) = rsCheckUser("Password") Then
      If UCase(Request.Form("txtUserPass")) = UCase(rsCheckUser("Password")) Then
            'If the password is correct then set the session variable to True
            Session("blnIsUserGood") = True
            session("Stremail")= strUserName
            session("Password")= strpassword
            session("Employee_id") = rsCheckUser("Employment_ID")
            Session("First_name") =  rsCheckUser("First_name")
            Session("USER") =  rsCheckUser("Type_Of_Access")

            'Close Objects before redirecting
            Set adoCon = Nothing
            Set strCon = Nothing
            Set rsCheckUser = Nothing
            
            'Redirect to the authorised user page and send the users name
             IF request.form("C1") = "ON" then
             Response.Cookies("Email") = strUserName
             end if
             Response.Redirect"staffmainpage.asp"
             
      End If
End If
            
'Close Objects
Set adoCon = Nothing
Set strCon = Nothing
Set rsCheckUser = Nothing
      
'If the script is still running then the user must not be authorised
Session("blnIsUserGood") = False

'Redirect to the unautorised user page
Response.Redirect"unauthorised_user_page.asp"
%>
0
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 150 total points
Comment Utility
0
 

Author Comment

by:eteran
Comment Utility
Here is a the check box from the form


<input type="checkbox" name="C1" value="ON">
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Eteran--

Did you spend any time reading my posts above?

FtB
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
You may also wish to try this instead in case you are using method=get

IF request("C1") = ..... then
0
 

Author Comment

by:eteran
Comment Utility
okay change the value to storeEmail and still nothing.
the value is erelevent. My code is just not working.
0
 

Author Comment

by:eteran
Comment Utility
form value
<input type="checkbox" name="C1" value="storeEmail">
Create cookie
 IF request.form("C1") = "storeEmail" then
             Response.Cookies("Email") = strUserName
             end if
             Response.Redirect"staffmainpage.asp"
Still not working
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Perhaps you need to add an expiry date to your cookie?

  IF request.form("C1") = "ON" then
                   Response.Cookies("Email") = strUserName
                    Response.Cookies("Email").Expires=#September 30,2004#
           end if
           Response.Redirect"staffmainpage.asp"
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Also, just for testing:

  IF request.form("C1") = "ON" then
                   Response.Cookies("Email") = "Eteran"
                    Response.Cookies("Email").Expires=#September 30,2004#
           end if
           Response.Redirect"staffmainpage.asp"
0
 

Author Comment

by:eteran
Comment Utility
okAY change has been made. Still no data from the cookie checker you gave me.
0
 

Author Comment

by:eteran
Comment Utility
I am also loking through my cookie folder andf I am not seeing anything
0
 

Author Comment

by:eteran
Comment Utility
Code       
 IF request.form("C1") = "storeEmail" then
             Response.Cookies("Email").Expires=#September 30,2004#
             Response.Cookies("Email") = strUserName
             end if
             Response.Redirect"staffmainpage.asp"
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
How do you post your form?
GET or POST?

hongjun
0
 

Author Comment

by:eteran
Comment Utility
Question. Can the cookie be called "email"; dose this cuase any conflicts.
0
 

Author Comment

by:eteran
Comment Utility
POst

<form name="Login" method="post" action="check_user.asp">
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
No, it will not conflict.

Try this

Response.Write "I am here<br>"
 IF request.form("C1") = "storeEmail" then
           Response.Write "Here am i<br>"
           Response.Cookies("Email").Expires=#September 30,2004#
           Response.Cookies("Email") = strUserName
           end if
           Response.Redirect"staffmainpage.asp"


To see if you ever print out "I am here" since the IF is inside anothe IF.


hongjun
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
If you can't get this working, I would suggest that you create a new test page that just has this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

<%
Response.Cookies("strTest") = "Eteran"
Response.Cookies("strTest").Expires=#September 30,2004#
%>
</HEAD>

<BODY>
<h3>Cookie Checker</h3>

<%
dim strCookieName, strKeyName
for each strCookieName in Request.Cookies
     if request.Cookies(strCookieName).HasKeys then
          for each strKeyName in Request.Cookies(strCookieName)
               response.write(strCookieName & "(" & strKeyName & ") = " & request.cookies(strCookieName)(strKeyName) & "<BR>")
          next
     else
          response.write(strCookieName & " = " & request.cookies(strCookieName) & "<BR>")
     end if
next
%>
</BODY>
</HTML>
0
 

Author Comment

by:eteran
Comment Utility
It is printing the info
0
 

Author Comment

by:eteran
Comment Utility
<%

'Dimension variables
Dim adoCon             'Database Connection Variable
Dim strCon            'Holds the Database driver and the path and name of the database
Dim rsCheckUser             'Database Recordset Variable
Dim strAccessDB       'Holds the Access Database Name
Dim strSQL             'Database query sring
Dim strUserName       'Holds the user name

'Initalise the strUserName variable
strUserName = Request.Form("txtUserName")
strpassword = request.form("txtUserPass")
'Check the database to see if user exsits and read in there password
'Initialise the strAccessDB variable with the name of the Access Database
strAccessDB = "ctinter"

'Create a connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
                  
'Database connection info and driver
strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=F:\hshome\ctinter\Data\ctinter.mdb"

'Set an active connection to the Connection object
adoCon.Open strCon

'Create a recordset object
Set rsCheckUser = Server.CreateObject("ADODB.Recordset")

'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM T_employees WHERE Company_Email ='" & strUserName & "' and Disable = 0"

'Query the database
rsCheckUser.Open strSQL, strCon

Response.Write (" & strUserName & ")
 IF request.form("C1") = "storeEmail" then
             Response.Cookies("staffemail").Expires=#September 30,2004#
             Response.Cookies("staffemail") = strUserName
end if
0
 
LVL 33

Accepted Solution

by:
hongjun earned 150 total points
Comment Utility
Response.Write (" & strUserName & ")
 IF request.form("C1") = "storeEmail" then
           Response.Write "I am here"
           Response.Cookies("staffemail").Expires=#September 30,2004#
           Response.Cookies("staffemail") = strUserName
           Response.Write "Cookies = " & Request.Cookies("staffemail") & "<br>"
end if



hongjun
0
 

Author Comment

by:eteran
Comment Utility
OKay Tried that Frizt, it work. My other code does not work :(
0
 

Author Comment

by:eteran
Comment Utility
this is what it printed

& strUserName &
0
 

Author Comment

by:eteran
Comment Utility
Okay got it. For some reason the value was On and I changed to storeemail and it still comes out as on. I left it that way and got it to work.

How do I make the cookie last 30 days.

And in the logon page how do I make it check the cookie and post it ont he field.
0
 

Author Comment

by:eteran
Comment Utility
Date + 30

wouyld that work for the date
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
My mistake
should be
     Response.Write (strUserName)
and not
     Response.Write (" & strUserName & ")


 Date + 30
would work

but i remember FtB says that is not preferred. Below is better
DateAdd("d", 10, Now)


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
mistake again
should be
    DateAdd("d", 30, Now)
0
 

Author Comment

by:eteran
Comment Utility
that is it  
Response.Cookies("staffemail").Expires= DateAdd("d", 30, Now)
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
>> For some reason the value was On and I changed to storeemail and it still comes out as on.
Something to do with cache?
Try a Ctrl-F5 for a hard reload.

hongjun
0
 

Author Comment

by:eteran
Comment Utility
what do I do to get the cookie value
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
post ur latest html and asp code in full again.
0
 

Author Comment

by:eteran
Comment Utility
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Welcome To South Florida's Real Estate Solution</title>
</head>

<body>

<table border="0" width="100%" id="table1">
      <tr>
            <td align="center">

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="760" id="AutoNumber21">
  <tr>
    <td width="100%"><span lang="en-us"> <!--#include file = "include\header.html" --></span></td>
  </tr>
</table>
<table id="AutoNumber19" style="BORDER-COLLAPSE: collapse" borderColor="#111111" cellSpacing="0" cellPadding="0" width="760" bgColor="#ffffff" border="0">
  <tr>
    <span align="center">
    <td width="314" height="420">
    <div align="center">
      <center>
      <table id="AutoNumber6" style="BORDER-COLLAPSE: collapse" borderColor="#111111" cellSpacing="0" cellPadding="0" width="300" bgColor="#ffffff" border="0">
        <tr>
          <td width="100%" colspan="3">
          <p align="center"><b><font face="Arial" size="2">Welcome to CTVO<br>
          CT's Virtual Office.</font></b></td>
        </tr>
        <tr>
          <td width="34%" bgcolor="#89AE79">
    &nbsp;</td>
          <td width="33%" bgcolor="#C4DFB0">
    &nbsp;</td>
          <td width="33%" bgcolor="#89AE79">
    &nbsp;</td>
        </tr>
        <tr>
          <td width="100%" colspan="3">
    <p align="center">
    <span style="font-size: 10.0pt; font-family: Arial; color: black; font-weight: 700">
    Where everything is at your fingertips! </span></td>
        </tr>
      </table>
      </center>
    </div>
    </td>
    <td width="446" height="420">
    <table id="AutoNumber7" style="BORDER-COLLAPSE: collapse" borderColor="#111111" height="407" cellSpacing="0" cellPadding="0" width="99%" border="0">
      <tr>
        <td width="100%" height="268">
        <p align="center">
    <span align="center">
        <b><font face="Arial" size="2"><img border="0" src="SAign.jpg"></font></b></span></p>
        <div align="center">
          <center>
          <table id="AutoNumber8" style="FONT-WEIGHT: bold; BORDER-COLLAPSE: collapse" borderColor="#796448" cellSpacing="0" cellPadding="4" width="408" bgColor="#f4f8e1" border="1">
            <tr>
              <td width="398">
              <table id="AutoNumber11" style="BORDER-COLLAPSE: collapse" borderColor="#ada592" cellSpacing="0" cellPadding="4" width="100%" border="1">
                <tr>
                  <td width="100%">
                  <p align="center">
    <span align="center">
    <b><font face="Arial" size="2">Login</font></b></span></p>
                  <form name="Login" method="post" action="check_user.asp">
  <div align="center">
    <center>
  <table width="320" border="0" cellpadding="2" bgcolor="#F4F8E1" style="border-collapse: collapse" bordercolor="#111111" height="132">
    <tr>
      <td align="right" height="43" valign="bottom" width="126"><b>
      <font size="2" face="Arial" color="#89AE79">Company Email: </font></b> </td>
      <td height="43" valign="bottom" width="187">

     <input type="text" name="txtUserName" size="28"></td>
    </tr>
    <tr>
      <td align="right" width="126" height="19">
            <span align="center">
            <input type="checkbox" name="C1" value="ON"></span></td>
      <td width="187" height="19">
        <font size="2" color="#89AE79">Remember my email.</font></td>
    </tr>
    <tr>
      <td align="right" width="126" height="19"><b>
      <font face="Arial" style="font-size: 9pt" color="#FF0000">Example:</font></b></td>
      <td width="187" height="19">
        <font color="#FF0000">(johndoe@ct.com)</font></td>
    </tr>
    <tr>
      <td align="right" width="126" height="22"><b>
      <font size="2" face="Arial" color="#89AE79">Password: </font></b> </td>
      <td width="187" height="22">
        <input type="password" name="txtUserPass" size="28"></td>
    </tr>
    <tr>
    <span align="center">
      <td align="right" width="126" height="19"><b>
      <font face="Arial" style="font-size: 9pt" color="#FF0000">Password:</font></b></td>
      <td width="187" height="19">
        <font color="#FF0000">(Your company password)</font></td>
    </span>
    </tr>
    <tr>
      <td align="right" height="40" width="126">&nbsp;</td>
      <td height="40" width="187">
        <input type="submit" name="Submit" value="Enter">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="reset" name="Submit2" value="Reset">
      </td>
    </tr>
    </table>
    </center>
  </div>
</form>
                  </td>
                </tr>
              </table>
              </td>
            </tr>
          </table>
          </center>
        </div>
        </td>
      </tr>
      </table>
    </td>
    </span>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="760" id="AutoNumber20">
  <tr>
    <td width="100%"><span lang="en-us"> <!--#include file = "include\footer.html" --></span>&nbsp;</td>
  </tr>
</table>
</td>
      </tr>
</table>
<p>&nbsp;</p>

</body>

</html>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>.On and I changed to storeemail and it still comes out as on<<

That is why I told you to change the checkbox value to something very different above.

FtB
0
 

Author Comment

by:eteran
Comment Utility
i know., i did but it did not catch it
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
From your last posted HTML code, i code this short simple code and it works for me..
It will go into the if statement when you check it.

<%
strUserName = Request.Form("txtUserName")

Response.Write ("strUserName = " & strUserName & "<br>")
 IF request.form("C1") = "ON" then
           Response.Cookies("staffemail").Expires=#September 30,2004#
           Response.Cookies("staffemail") = strUserName
         Response.Write Request.Cookies("staffemail")
end if
%>


hongjun
0
 

Author Comment

by:eteran
Comment Utility
I got it to work.

The question is how do I get the value and have it check wheter the cookie is there or not if so then post the email in the username box

  <input type="text" name="txtUserName" size="28">
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
<%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies("staffemail")) then%>
    input type="text" name="txtUserName" size="28" value="<%=Request.Cookies("staffemail")%>">
<%else%>
   <input type="text" name="txtUserName" size="28">
<%end if%>

FtB
0
 

Author Comment

by:eteran
Comment Utility
I am getting the an error. Error is posted below the code
     
<%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies('staffemail')) then
    Response.write ("input type='text' name='txtUserName' size='28' value='Request.Cookies("staffemail")'>")%>
    <%else%>
    <input type="text" name="txtUserName" size="28">
    <%end if%>
-------------errror---------------------------------------------error----------------------------------------------
Microsoft VBScript compilation error '800a03ea'

Syntax error

/ctinter.worldispnetwork.com.hs/StaffLogonpage.asp, line 78

If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies('staffemail')) then
---------------------------------------------------------------------------------------------------------------------^
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
This:

isEmpty(Request.Cookies('staffemail')) then

Should be this:

isEmpty(Request.Cookies("staffemail")) then


in other words, use the " delimiter rather than the ' delimiter.

FtB
0
 

Author Comment

by:eteran
Comment Utility
would this work
Response.write ("input type='text' name='txtUserName' size='28' value='Request.Cookies('staffemail")'>")%>
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
No it would not. This should work better:

<%Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies('staffemail") & "'>")%>

FtB
0
 

Author Comment

by:eteran
Comment Utility
The code below is what I am using. IT look fine to me. When I run the page it does not load the cookie info on the page.
 
    <%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies("staffemail")) then
   Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")%>
    <%else%>
    <input type="text" name="txtUserName" size="28">
    <%end if%>
0
 

Author Comment

by:eteran
Comment Utility
here si the code int he cookie stored in my computer
staffemail
eteran%40ct%2Ecom
ct.worldispnetwork.com/ct.worldispnetwork.com.hs
1536
3742523904
29670301
3339155264
29664266
*
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
What happens if you put my cookie reader text near the top of your page, what does it output?

Also, I wonder if you need to decrypt your email address like this:

 Response.write ("<input type='text' name='txtUserName' size='28' value='" & escape(Request.Cookies("staffemail")) & "'>")%>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Oops, that should be:

Response.write ("<input type='text' name='txtUserName' size='28' value='" & unescape(Request.Cookies("staffemail")) & "'>")%>
0
 

Author Comment

by:eteran
Comment Utility
nOTHING COMES OUT WERED
0
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 200 total points
Comment Utility
With this line, nothing comes out?

Response.write ("<input type='text' name='txtUserName' size='28' value='" & unescape(Request.Cookies("staffemail")) & "'>")%>

FtB
0
 
LVL 15

Expert Comment

by:Thogek
Comment Utility
You shouldn't need to unencode the cookie value -- the call to Request.Cookies() will do that for you -- unless you explicitly encoded the value yourself when you first set it.

Also, if the ASP is using VBScript, I don't know that the escape/unescape functions will be available.  (Aren't those JavaScript functions.)  But, again, they shouldn't be necessary here, anyway.

eteran,
You say that "it does not load the cookie info on the page."  What exactly does appear within the textbox?  (Or in the source HTML?)  Anything?
0
 
LVL 15

Expert Comment

by:Thogek
Comment Utility
> ct.worldispnetwork.com/ct.worldispnetwork.com.hs

This line of your cookie file looks odd....

Question:
Is the page/URL that sets the cookie the same page/URL that is trying to read it?  If not, what are the two different URLs?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>>You shouldn't need to unencode the cookie value -- the call to Request.Cookies() will do that for you <<

I thought so too, but look at his cookie values:

staffemail
eteran%40ct%2Ecom

Perhaps they come from a request string?


>>Also, if the ASP is using VBScript, I don't know that the escape/unescape functions will be available.  (Aren't those JavaScript functions.) <<

Yes, that is what most people think, but give this a try:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="vbscript">
sub showMe()
      strString = unescape("eteran%40ct%2Ecom")
      msgbox strString

end sub
</script>
</HEAD>

<BODY onLoad="showMe()">

</BODY>
</HTML>


FtB

0
 
LVL 15

Expert Comment

by:Thogek
Comment Utility
Setting Response.Cookies to a string value causes ASP to encode the values using very much the same encoding structure as for a QueryString parameter (Server.UrlEncode), which is what you see in the cookie file.  Retrieving the cookie string via Request.Cookies automatically unencodes that value for you, in much the same way that Request.QueryString performs any necessary URL decoding for you.
0
 
LVL 15

Expert Comment

by:Thogek
Comment Utility
> Also, if the ASP is using VBScript, I don't know that the escape/unescape
> functions will be available.  (Aren't those JavaScript functions.)

My mistake.  Fritz the right.  VBScript did add escape and unescape functions somewhere along the way.
http://msdn.microsoft.com/library/en-us/script56/html/vsfctescape.asp
http://msdn.microsoft.com/library/en-us/script56/html/vsfctunescape.asp
0
 

Author Comment

by:eteran
Comment Utility
HERE IS THE CODE.
For some reason I can see the cookie in my computer under document setting in XP
     Any idea of what I can do.
<%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies("staffemail")) then
   'Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")
    Response.write ("<input type='text' name='txtUserName' size='28' value='" & escape(Request.Cookies("staffemail")) & "'>")
    else
   Response.write ("<input type='text' name='txtUserName' size='28'>")
    end if%>
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
why not you remove the IF statement and do this straight.

<%
Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")
%>



hongjun
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>>why not you remove the IF statement and do this straight.<<

Because that makes too much sense!!!

Good call,

FtB
0
 

Author Comment

by:eteran
Comment Utility
So anyo ne here can help.

Here is the info in the cookie

staffemail
enriqueteran%40ctinter%2Ecom
ct.worldispnetwork.com/ct.worldispnetwork.com.hs
1536
3742523904
29670301
3339155264
29664266
*
strTest
Eteran
ct.worldispnetwork.com/ct.worldispnetwork.com.hs
1536
437688320
29664955
83406080
29664270
*
0
 

Author Comment

by:eteran
Comment Utility
Anyone have any ideas has to what is going on with this
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
Your machine is a bit weird.
Cookie is created but is not printing as normal with FtB's reader code.
Weird..


hongjun
0
 

Author Comment

by:eteran
Comment Utility

I posted the code above. it is creting a cookie. I can see in my cookies. How do I get the value out.

     <%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies("staffemail")) then
   'Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")
    Response.write ("<input type='text' name='txtUserName' size='28' value='" & escape(Request.Cookies("staffemail")) & "'>")
    else
   Response.write ("<input type='text' name='txtUserName' size='28'>")
    end if%>
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
why not you remove the IF statement and do this straight.

<%
Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")
%>



hongjun
0
 

Author Comment

by:eteran
Comment Utility
still nothi9ng
0
 

Author Comment

by:eteran
Comment Utility
I just tried it in onther computer and nothing
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
it work on my machine and that's for sure.
i am running out of ideas.
0
 

Author Comment

by:eteran
Comment Utility
it does
0
 

Author Comment

by:eteran
Comment Utility
No way
same code works on your machine \
0
 

Author Comment

by:eteran
Comment Utility
Create cookie

IF request.form("C1") = "ON" then
           
           Response.Cookies("staffemail").Expires= DateAdd("d", 30, Now)
           Response.Cookies("staffemail") = strUserName
           Response.Write "Cookies = " & Request.Cookies("staffemail") & "<br>"
end if

Reterieve cookie

<%=Request.Cookies("staffemail")%>
     <%If Request.Cookies("staffemail") <> "" and not isNull(Request.Cookies("staffemail")) and not isEmpty(Request.Cookies("staffemail")) then
   'Response.write ("<input type='text' name='txtUserName' size='28' value='" & Request.Cookies("staffemail") & "'>")
    Response.write ("<input type='text' name='txtUserName' size='28' value='" & escape(Request.Cookies("staffemail")) & "'>")
    else
   Response.write ("<input type='text' name='txtUserName' size='28'>")
    end if%>
0
 
LVL 15

Expert Comment

by:gladxml
Comment Utility
I am not sure if you have tried the approach that I had posted... But it does work however... Anyway try to check out the link regarding cookies... might help...

http://www.w3schools.com/asp/asp_cookies.asp

Happy programming...

0
 

Author Comment

by:eteran
Comment Utility
i did not see your posting
0
 
LVL 10

Expert Comment

by:thefritterfatboy
Comment Utility
Cookies have to be set in the Headers. Some suggestions in this thread have response.write above the response.cookies. This is invalid syntax. You cannot set a cookie ater something has been written to a page. (Much the same as response.redirect)

Also - I have had trouble requesting cookie variables in the same script as I have set them. The cookies are requested + set in the HTTP headers.

ASP tends not to send cookie data unless you set an expiry date. If the cookie is a "session cookie" IIS will merely send a session ID and store the cookie on the server. (Regardless of whether you are using sessions or not) This is not true in every case but I have found it to be true in some of my projects.
0
 
LVL 1

Expert Comment

by:flatsheep
Comment Utility
I started reading this thread but realised how long it was, so gave up half way through.

What seemed apparant... If this helps:

When you set cookies using "response.cookies("var") = test" this only persists the cookie for the asp session.  You will not see the cookie output anywhere in the cookies folder, cause ie holds the data in memory, so I believe.

To set persistant cookies you'll have to use Javascript.  That's the only way I've seen it done with ASP.  ASP can read cookies set by javascript, that are set in it's domain.

DF
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>."response.cookies("var") = test" this only persists the cookie for the asp session<<

I don't believe that is true. You can set the expires property for long into the future.

FtB
0
 
LVL 10

Expert Comment

by:thefritterfatboy
Comment Utility
>> I don't believe that is true. You can set the expires property for long into the future.<<

It's a mystery to me. If you don't set the .Expires property, IIS doesn't appear to send the cookie data at all in some cases. (Check your log files if you have them to record headers. The only cookie sent each time is an ASP session ID.) If you do set the .Expires property, then IIS sends the cookie explicitly and IE stores it in the cookies folder.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I haven't tried using cookies without explicity setting the expires property, so I have no clue what will happen if you don't. On the other hand, I have used ASP cookies to persist login credentials for sites with low security needs.

FtB
0
 

Author Comment

by:eteran
Comment Utility
I still can not get jsut a basic thing to work
0
 
LVL 1

Expert Comment

by:flatsheep
Comment Utility
It's been so long since the thread was posted to.  What is the problem you are getting?  Is it an error, problem with the logic?

DF
0
 
LVL 1

Expert Comment

by:flatsheep
Comment Utility
Actually, going by your original email.  You can't set a persistent cookie in ASP.  The only way to do it is via JavaScript.  It's common to write a couple of functions to inject javascript into a page when you want to have a persistent cookie set.

DF
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>>Actually, going by your original email.  You can't set a persistent cookie in ASP.<<


Really? Why not? You can write a cookie and set an expiry date way into the future.

FtB
0
 

Author Comment

by:eteran
Comment Utility
OKay,
Sorry for the wait guys but it took me along time to figure this out and I had alot of work.

I am running of a secure website. If I disable my secure website and try the same code it work :).
Now the problem is that i NEED to have a secure website becuase I have vital informaiton going through it.
How can I work around the problkem.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Okay, there has been a lot of posting, a lot of time spent, and then a long time since you posted. How about you restate the problem as you understand it now so that we can start fresh?

FtB
0
 

Author Comment

by:eteran
Comment Utility
I am creating a username cookie. This cookie hold the email of the person that just logged on. The script I am useing works great so long as I do not go through the secure site https://xxxxx.xom. If I go through the http the cookie works fine. I wanted to know if there is any way to make this script work fromna secure soite. https.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Cookies work fine with https (although I hear the performance can be somewhat slower). You may have to write the cookie under the https credentials, however, to make this work.

FtB
0
 

Author Comment

by:eteran
Comment Utility
How do I go about doing that.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I don't know for sure that you have to do it this way, but if you set your cookie while you are in https, then https should be able to read it.

FtB
0
 

Author Comment

by:eteran
Comment Utility
IT is so confusing. It really works great whern I go through the nonsecure way http..... When i use the https way it does not work. I am on a shared https server do you think this has anything to do with it. And do you think the hosting company has blocked this feature,.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I doubt it. I would test for you here, but I don't have an https server handy.

why don't you try creating a simple test page that creates the cookie and then another that reads it. That way you can isolate the problem. Also, use my troubleshooting cookie reader:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<%
dim strCookieName, strKeyName
for each strCookieName in Request.Cookies
     if request.Cookies(strCookieName).HasKeys then
          for each strKeyName in Request.Cookies(strCookieName)
               response.write(strCookieName & "(" & strKeyName & ") = " & request.cookies(strCookieName)(strKeyName) & "<BR>")
          next
     else
          response.write(strCookieName & " = " & request.cookies(strCookieName) & "<BR>")
     end if
next
%>
</BODY>
</HTML>
0
 

Author Comment

by:eteran
Comment Utility
OKay, the code you posted I just tried it work under the http (non-secure site) of the website. I got to the same page through the secure site https and did dose not retirive the data. I even created the cookie through the https site and still did not retrieve it. Both cookies are siting in my cookie folders I can see them and open them to verify the data is there. There has to be somehting with the https server allowing a cookie to place it self there.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
What happens if you lower the security settings in your browser, any difference? I am wondering if this might have something to do with the browser settings as well?

FtB
0
 

Author Comment

by:eteran
Comment Utility
No nothing happens
I put it to the lowest it can go.
0
 
LVL 1

Expert Comment

by:flatsheep
Comment Utility
It must be a settings issue, or IIS "feature".  I'm running IIS 5.1 on XP prof.  I just ran a test script to check cookies over HTTP/HTTPS, and on all attempts the cookie is retained.  If I delete my cookies and go to https then the cookie is created, then opening another browser and going to http the cookie is still available.  

Try running your code/test script on a seperate machine.  See what happens.  If you're using IIS6 then there are loads of new default settings to alter, it is bolted down by default... in most cases.  I have access to an IIS6 box, but I'm not in work till next week.

The script below worked for me, try that instead of your code, just to rule it out the equation.

Heres my test script:

<%
If Len(Request.Cookies("test")) = 0 Then
      Response.Cookies("test") = 3
      Response.Cookies("test").Expires = DateAdd("n", 1, now())
Else
      Response.Write "Already set."
End If
%>
<html>
<body>
<h1>cookie example</h1>
<%=Request.Cookies("test")%>
</body>
</html>
0
 

Author Comment

by:eteran
Comment Utility
OKay ,GOt it it is a server setting.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
That's great!!

FtB
0
 
LVL 1

Expert Comment

by:flatsheep
Comment Utility
What setting specifically?  So people referencing this thread can try the fix that you did?

DF
0
 

Author Comment

by:eteran
Comment Utility
WELL, i DON'T HOST THE WEBPAGE BUT MY HOSTING COMPANY GAVEME THE HEADS UP NO SETTING ARE MENETIONED IN THE EMAIL .

SORRY
HOW DO i PRICE THIS QUESTION OUT IF ALL OF YOU WHERE RIGHT.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Use the split link near the bottom of the thread to split the points among those who helped you.

http://www.experts-exchange.com/help.jsp#hi69



FtB
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now