2

One my home works in my classic ASP class is to create a simple logon form, a page that processes the form by saving values to cookies, and then a display page that takes the values from the cookie, stores them into session variables and then displays the results in an html page.

I have found that this homework works properly in IE, Chrome, Opera, Safari, Maxthon, Avant and SOME versions / installations of Firefox. This has baffled me greatly. Firefox has been my browser of choice for a couple of years now. I have Firefox 5 and 9 at home, on Win7 64 bit machines. And everything returns as "undefined" on these two machines. The Win XP 32 bit / Firefox on the machines at school render this homework properly. This leads me to believe that the 64bit OS - Firefox combination is the problem.

Here's my code:

Register.asp

    <form name="frmLogon" id="frmLogon" method="post" action="session.asp">

        <h3>Logon</h3>  

                <label for="txtUserName">
                    Username:
                    <input type="text" name="txtUserName" maxlength="20" />
                </label>

                <br /><br />

                <label for="txtPassword">
                    Password:
                    <input type="text" name="txtPassword" maxlength="20" />
                </label>

                <input type="hidden" name="hidSessionID" value="Session.SessionID"/>

                <br /><br />

        <center>
            <input type="submit" value="Submit" name="btnSubmit"/>
            <input type="reset" value="Reset" name="btnReset" />
        </center>

    </form>

</body>

Session.asp

<body>

<%   
    // Populate the cookie      
    Response.Cookies("registration")("UserName") = Request.Form("txtUserName");
    Response.Cookies("registration")("Password") = Request.Form("txtPassword");
    Response.Cookies("registration")("SessionID") = Session.SessionID;
    Response.Cookies("registration")("Date") = Date();
    Response.Cookies("registration")("Referer") = Request.ServerVariables("HTTP_REFERER");
    Response.Cookies("registration")("RemoteIP") = Request.ServerVariables("REMOTE_ADDR");

    // script required to set expiration date. (Not shown in textbook or sample code...)        
    var dtmDate;
    dtmDate = new Date()
    intMonth = dtmDate.getMonth() + 1
    dtmDate.setDate(dtmDate.getDate() + 7)
    strExpireDate = intMonth + "/" + dtmDate.getDate() + "/" + dtmDate.getFullYear()
    Response.Cookies("registration").Expires = strExpireDate

    Response.Redirect("Display.asp");
%>
</body>

Display.asp

<body>

<%
Break();
Response.write("<font color='blue'>The cookies keys and values:</font>");
Break();
Response.write("UserName: " + (Request.cookies("registration")("UserName")));
Break();
Response.write("Password: " + (Request.cookies("registration")("Password")));
Break();
Response.write("SessionID: " + (Request.cookies("registration")("SessionID")));
Break();
Response.write("Date: " + (Request.cookies("registration")("Date")));
Break();
Response.write("Referer: " + (Request.cookies("registration")("Referer")));
Break();
Response.write("RemoteIP: " + (Request.cookies("registration")("RemoteIP")));
Break();
Response.write("<hr />");
Break();

// Assign the cookie values to Session variables              
Session("UserName") = Request.Cookies("registration")("UserName")
Session("Password") = Request.Cookies("registration")("Password")
Session("SessionID") = Request.Cookies("registration")("SessionID")
Session("Date") = Request.Cookies("registration")("Date")
Session("Referer") = Request.Cookies("registration")("Referer")
Session("RemoteIP") = Request.Cookies("registration")("RemoteIP")


// Display the session variables populated from the cookie.
Response.write("<font color='blue'>The session variables, populated by the cookies keys and values:</font>");
Break();
Response.write("UserName: " + Session("UserName"))
Break();
Response.write("Password: " + Session("Password"))
Break();
Response.write("SessionID: " + Session("SessionID"))
Break();
Response.write("Date: " + Session("Date"))
Break();
Response.write("Referer: " + Session("Referer"))
Break();
Response.write("Remote IP: " + Session("RemoteIP"))
Break();
Response.write("<hr />");
Break();

// Display the session variables populated from the cookie.
Response.write("<font color='blue'>The unformatted output of the 'Response.Write(Request.ServerVariables('HTTP_COOKIE'))' command:</font>");
Break();
Response.Write(Request.ServerVariables("HTTP_COOKIE"))

function Break()
{
    Response.write("<br></br>")
}

%>


</body>

Can anyone explain why this entire exercise returns "undefined" variables only in Firefox on Win 7 64 bit?

Matthew Carr
  • 105
  • 10
  • Seems like browser does not accept the cookies. – Kul-Tigin Jan 25 '12 at 09:34
  • If this problem only occurs in a specific browser, it would seem to be a client-side issue. The most probable cause being that the browser doesn't accept cookies. Sessions need a cookie to work. In most browser-preferences you can have the browser ask before setting each cookie, making it easier for you to debug. – Erik Oosterwaal Apr 05 '12 at 14:29
  • Try http://support.mozilla.org/en-US/kb/Enabling%20and%20disabling%20cookies – suraj jain Apr 11 '12 at 06:22

1 Answers1

0

First, WHY are you writing that all to cookie? Why not write that all directly to session. Cookies can provide security risk in the username and password later. I think it would be better to set all the session variables in "session.asp", but I guess that may be personal...

Back to your question, it is most likely that "Cookies" are disabled. Click here to learn about enabling cookies in firefox.

grepsedawk
  • 3,324
  • 2
  • 26
  • 49