Check this code

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
eteranAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
ThogekCommented:
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
 
eteranAuthor Commented:
ON
0
 
eteranAuthor Commented:
Does the rest sound fine
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
hongjunCommented:
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
 
gladxmlCommented:
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
 
ThogekCommented:
> 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
 
fritz_the_blankCommented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
Where can I check to see if the cookie has been created. I have wind\ow XP
0
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
Nothing comes out
0
 
hongjunCommented:
if it's there, then FtB code will read and display it
0
 
eteranAuthor Commented:
            IF request.form("C1") = "ON" then
             Response.Cookies("Email") = strUserName
             end if
             Response.Redirect"staffmainpage.asp"
0
 
hongjunCommented:
you need to allow cookies
0
 
eteranAuthor Commented:
<%
'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
 
eteranAuthor Commented:
Here is a the check box from the form


<input type="checkbox" name="C1" value="ON">
0
 
fritz_the_blankCommented:
Eteran--

Did you spend any time reading my posts above?

FtB
0
 
hongjunCommented:
You may also wish to try this instead in case you are using method=get

IF request("C1") = ..... then
0
 
eteranAuthor Commented:
okay change the value to storeEmail and still nothing.
the value is erelevent. My code is just not working.
0
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
okAY change has been made. Still no data from the cookie checker you gave me.
0
 
eteranAuthor Commented:
I am also loking through my cookie folder andf I am not seeing anything
0
 
eteranAuthor Commented:
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
 
hongjunCommented:
How do you post your form?
GET or POST?

hongjun
0
 
eteranAuthor Commented:
Question. Can the cookie be called "email"; dose this cuase any conflicts.
0
 
eteranAuthor Commented:
POst

<form name="Login" method="post" action="check_user.asp">
0
 
hongjunCommented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
It is printing the info
0
 
eteranAuthor Commented:
<%

'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
 
hongjunCommented:
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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
eteranAuthor Commented:
OKay Tried that Frizt, it work. My other code does not work :(
0
 
eteranAuthor Commented:
this is what it printed

& strUserName & 
0
 
eteranAuthor Commented:
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
 
eteranAuthor Commented:
Date + 30

wouyld that work for the date
0
 
hongjunCommented:
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
 
hongjunCommented:
mistake again
should be
    DateAdd("d", 30, Now)
0
 
eteranAuthor Commented:
that is it  
Response.Cookies("staffemail").Expires= DateAdd("d", 30, Now)
0
 
hongjunCommented:
>> 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
 
eteranAuthor Commented:
what do I do to get the cookie value
0
 
hongjunCommented:
post ur latest html and asp code in full again.
0
 
eteranAuthor Commented:
<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
 
fritz_the_blankCommented:
>.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
 
eteranAuthor Commented:
i know., i did but it did not catch it
0
 
hongjunCommented:
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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
<%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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
would this work
Response.write ("input type='text' name='txtUserName' size='28' value='Request.Cookies('staffemail")'>")%>
0
 
fritz_the_blankCommented:
No it would not. This should work better:

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

FtB
0
 
eteranAuthor Commented:
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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
fritz_the_blankCommented:
Oops, that should be:

Response.write ("<input type='text' name='txtUserName' size='28' value='" & unescape(Request.Cookies("staffemail")) & "'>")%>
0
 
eteranAuthor Commented:
nOTHING COMES OUT WERED
0
 
fritz_the_blankCommented:
With this line, nothing comes out?

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

FtB
0
 
ThogekCommented:
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
 
ThogekCommented:
> 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
 
fritz_the_blankCommented:
>>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
 
ThogekCommented:
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
 
ThogekCommented:
> 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
 
eteranAuthor Commented:
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
 
hongjunCommented:
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
 
fritz_the_blankCommented:
>>why not you remove the IF statement and do this straight.<<

Because that makes too much sense!!!

Good call,

FtB
0
 
eteranAuthor Commented:
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
 
eteranAuthor Commented:
Anyone have any ideas has to what is going on with this
0
 
hongjunCommented:
Your machine is a bit weird.
Cookie is created but is not printing as normal with FtB's reader code.
Weird..


hongjun
0
 
eteranAuthor Commented:

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
 
hongjunCommented:
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
 
eteranAuthor Commented:
still nothi9ng
0
 
eteranAuthor Commented:
I just tried it in onther computer and nothing
0
 
hongjunCommented:
it work on my machine and that's for sure.
i am running out of ideas.
0
 
eteranAuthor Commented:
it does
0
 
eteranAuthor Commented:
No way
same code works on your machine \
0
 
eteranAuthor Commented:
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
 
gladxmlCommented:
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
 
eteranAuthor Commented:
i did not see your posting
0
 
thefritterfatboyCommented:
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
 
flatsheepCommented:
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
 
fritz_the_blankCommented:
>."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
 
thefritterfatboyCommented:
>> 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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
I still can not get jsut a basic thing to work
0
 
flatsheepCommented:
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
 
flatsheepCommented:
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
 
fritz_the_blankCommented:
>>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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
How do I go about doing that.
0
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
eteranAuthor Commented:
No nothing happens
I put it to the lowest it can go.
0
 
flatsheepCommented:
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
 
eteranAuthor Commented:
OKay ,GOt it it is a server setting.
0
 
fritz_the_blankCommented:
That's great!!

FtB
0
 
flatsheepCommented:
What setting specifically?  So people referencing this thread can try the fix that you did?

DF
0
 
eteranAuthor Commented:
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
 
fritz_the_blankCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.