www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Cookie Problem

  1. #1
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94

    Cookie Problem

    I have a techincal support form. And when the user hits submit i want to give
    them a cookie. When they try to access this page again in a 24-48 hour time I
    want the page to identify the cookie and redirect them to an alternative
    page. Yet i am having a problem with the page.




    Here is my full code:





    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_validateForm() { //v4.0
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
    } else if (test!='R') { num = parseFloat(val);
    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
    if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
    min=test.substring(8,p); max=test.substring(p+1);
    if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>

    <%
    Response.Expires = -1000 'Make sure the browser doesnt cache this page
    Response.Buffer = True 'enables our response.redirect to work

    dim show, verify

    verify = "test"

    show = Request.Cookies("workplz")

    If verify = show
    Then Response.Redirect "http://www.google.com"

    End If

    If Request.Form("valuepassed") ="true" Then
    Mailform
    Else
    Techform
    End If

    Sub Mailform
    'Dim queinfo, questr


    Dim prod
    prod = "test"

    Response.Cookies("workplz")= prod
    Response.Cookies("workplz").Expires = Date + 1

    Dim myMail
    Set myMail = CreateObject("CDONTS.NewMail")
    HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL
    HTML = HTML & "<html>"
    HTML = HTML & "<head>"
    HTML = HTML & "<title>Tech Form</title>"
    HTML = HTML & "</head>"
    HTML = HTML & "<center><b>Tech Form</b></center>"
    HTML = HTML & "<br> <b>Name: </b>" & Request.Form("Name")
    HTML = HTML & "<br> <b>Email: </b>" & Request.Form("Email")
    HTML = HTML & "<br> <b>Operating System: </b>" & Request.Form("OS")
    HTML = HTML & "<br> <b>Order Number: </b>" & Request.Form("Order")
    HTML = HTML & "<br> <b>RAM: </b>" & Request.Form("RAM")
    HTML = HTML & "<br> <b>Connection: </b>" & Request.Form("Connection")
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"

    myMail.From = "test@test.com"
    myMail.To = Request.Form("Email")
    myMail.Subject = "Re: Tech Form"
    myMail.BodyFormat = 0
    myMail.MailFormat = 0
    myMail.Body = HTML
    myMail.Send
    Response.Redirect "http://www.yahoo.com"

    Techform
    End Sub
    %>


    <% Sub Techform %>
    <body bgcolor="#ffffff">
    <form name="form" action="rr.asp" method="post">
    <input type="hidden" name="valuepassed" value="true">
    <table width="576" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="574" valign="top"><table width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td colspan="2"><div align="center"><strong><FONT face="Arial, Helvetica, sans-serif" size="4">Tech Form </FONT></strong><br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <p><FONT face="Arial, Helvetica, sans-serif" size="2">Provide as much information
    as
    possible
    so we can answer the question quickly and accurately.</FONT></p>
    </div></td>
    </tr>
    <tr>
    <td colspan="2"><table width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="34%"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Your Name <font color="#FF0000">*</font></strong></font></td>
    <td width="35%"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Email
    Address<font color="#FF0000">*</font></strong></font></td>
    <td width="31%"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Windows OS</strong></font></td>
    </tr>
    <tr>
    <td><font face="Arial, Helvetica, sans-serif">
    <INPUT type="text" name="Name" size="25" maxlength="40">
    </font></td>
    <td><font face="Arial, Helvetica, sans-serif">
    <INPUT name="Email" type="text" id="Email" onBlur="MM_validateForm('Email','','RisEmail');return document.MM_returnValue" size="25" maxlength="40">
    </font></td>
    <td><FONT color="#FF0000" face="Arial, Helvetica, sans-serif">
    <SELECT name="OS">
    <OPTION>Windows 3.1</OPTION>
    <OPTION>Windows 95</OPTION>
    <OPTION>Windows NT</OPTION>
    <OPTION>Windows 98</OPTION>
    <OPTION>Windows ME</OPTION>
    <OPTION>Windows 2000</OPTION>
    <OPTION selected>Windows XP</OPTION>
    <OPTION>Windows 2003</OPTION>
    </SELECT>
    </FONT></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><font face="Arial, Helvetica, sans-serif"><strong><FONT size="2">Order Number <font color="#FF0000">*</font>&nbsp;</FONT></strong></font></td>
    <td><div align="left"><font face="Arial, Helvetica, sans-serif"><strong><FONT size="2">Amount
    of RAM?</FONT></strong></font></div></td>
    <td><font face="Arial, Helvetica, sans-serif"><strong><FONT color="#FF0000"><FONT color="#000000" size="2">Connection
    Speed?</FONT></FONT></strong></font></td>
    </tr>
    <tr>
    <td><FONT face="Arial, Helvetica, sans-serif" size="2">
    <INPUT name="Order" type="text" id="Order" onBlur="MM_validateForm('Email','','RisEmail','Product','','R');return document.MM_returnValue" size="25" maxlength="12">
    </FONT></td>
    <td><font face="Arial, Helvetica, sans-serif">
    <INPUT name="RAM" type="text" id="RAM" size="25" maxlength="25">
    </font></td>
    <td><FONT color="#FF0000" face="Arial, Helvetica, sans-serif"><B>
    <select name="Connection">
    <option selected>Dial Up</option>
    <option>DSL</option>
    <option>Cable</option>
    <option>T1</option>
    <option>T3</option>
    </select>
    </B></FONT></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td colspan="2"><font face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr>
    <td><div align="center">
    <font face="Arial, Helvetica, sans-serif">
    <input name="Submit" type="submit" onClick="MM_validateForm('Name','','R','Email','','RisEmail','Order','','R');return document.MM_returnValue" value="Submit">
    </font></div></td>
    <td><div align="center">
    <font face="Arial, Helvetica, sans-serif">
    <input type="reset" name="Reset" value="Reset Form">
    </font></div></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center"><br>
    <font color="#0000FF" size="2" face="Arial, Helvetica, sans-serif">** Our technical support team <strong></strong>has a normal response time of less than 1 business day. Depending on support volume and customer&rsquo;s it could take up to 3 business days **</font></div></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </form>
    <% End Sub%>

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637

    Re: Cookie Problem

    Originally posted by Athmaus
    Yet i am having a problem with the page.
    You gonna do more than just outline the scenario and provide boat-loads of code? How about error messages or other symptomatic erroneous results?

  3. #3
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    see here lies the problem....

    All i know is the problem is located with the Cookie code (request or response), i am unsure which line as i am with IT as well trying to get it fixed so i can debug it.

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    OK, I think maybe you're refering to the expiration of the Cookie not being what you want it to be. This is the problem:

    Response.Cookies("workplz").Expires = Date + 1

    That will not give you a Cookie that expires one day from today. If it works, then it probably gives you a Cookie that expires one milli-second or one second from the current time.

    Check out the DateAdd function.

  5. #5
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    I edited that and i still get the same error....

    I believe my problem lies with this part:

    dim show, verify

    verify = "reg"

    show = Request.Cookies("3breg")

    If verify = show
    Then Response.Redirect "http://www.google.com"

    Else

    If Request.Form("valuepassed") ="true" Then
    Mailform


    Where i am tryin to find the cookie and read it

  6. #6
    Join Date
    Dec 2004
    Posts
    8,637
    What error? You didn't mention anything previously about getting errors! I specifically asked you that question.
    Originally posted by Athmaus
    I edited that...
    Show what you edited.

  7. #7
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    Originally posted by phpnovice
    What error? You didn't mention anything previously about getting errors! I specifically asked you that question.

    Show what you edited.
    and i freakin answered it here: All i know is the problem is located with the Cookie code (request or response), i am unsure which line as i am with IT as well trying to get it fixed so i can debug it. All iget is an Internal Server Error.

    I do not know WHERE the error is exactly at the moment until the techs fix the "friendly" error page on the server. All i know that it is with the Request.Cookies OR Response.Cookies. If i take both out the form works fine.

  8. #8
    Join Date
    Dec 2004
    Posts
    8,637
    Originally posted by Athmaus
    ... until the techs fix the "friendly" error page on the server.
    This does not require a "tech". You must be using IE. Go here:

    Tools / Internet Options... / Advanced / Browsing

    and make sure this is unchecked:

    Show friendly HTTP error messages

    Otherwise: Show what you edited!

  9. #9
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    Originally posted by phpnovice
    This does not require a "tech". You must be using IE. Go here:

    Tools / Internet Options... / Advanced / Browsing

    and make sure this is unchecked:

    Show friendly HTTP error messages

    Otherwise: Show what you edited!
    Well duh! It it unchecked. LIke i said a tech is in process of fixin it.

    And the "edited" part is what you asked me to try the DateAdd function. that is all........

  10. #10
    Join Date
    Dec 2004
    Posts
    8,637
    Originally posted by Athmaus
    And the "edited" part is what you asked me to try the DateAdd function. that is all........
    Yes, but I want to see how you coded it.

  11. #11
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    Dim prod, xdate
    prod = "test"

    xdate = Now()

    Response.Cookies("workplz")= "test"
    Response.Cookies("workplz").Expires = DateAdd("d", 7, xdate)
    Last edited by Athmaus; 03-16-2005 at 02:49 PM.

  12. #12
    Join Date
    Dec 2004
    Posts
    8,637
    Definitely need actual error message information -- rather than just guessing.
    Try changing this:
    Code:
    If verify = show
    Then Response.Redirect "http://www.google.com"
    
    End If
    to this:
    Code:
    If verify = show Then
        Response.Redirect "http://www.google.com"
    End If

  13. #13
    Join Date
    Dec 2004
    Posts
    8,637
    I also believe that you cannot do a Redirect if you have already sent some HTML to the client.

  14. #14
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    The techs fixed the problem with the friendly errors.

    I left out an "End If" statement in the beginning. Once i put the end If after the first end if, the entire thing works.

    Thanks for your help.

  15. #15
    Join Date
    Apr 2004
    Location
    TX
    Posts
    94
    Hey!

    I have another problem now. I have another cookie that users will get when they get to our ecom. Hwo can i read this cookie on the form. I made the cookie on the ecom but i do not know how to access it on these forms since it is made on another domain.....


    I found this but to be honest snippit online, I am at a loss here

    <%

    UID=Request.Cookies("UID")

    If ((IsNull(UID)) OR (Len(UID)=0)) Then

    strURL=Request.ServerVariables("URL"))
    strQueryString=Request.ServerVariables("QUERY_STRING"))


    If (Len(strQueryString)>0) Then
    strReturn= Server.URLEncode(strURL & "?" & strQueryString)
    Else
    strReturn= Server.URLEncode(strURL)
    End If

    Respone.Redirect("http://myserver.com/slave.asp?Return=" & strReturn)

    End If
    %>

    All i need to do is read the cookie from another domain that i named "test" than make sure it has "yes" as the value.

    Any ideas?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles