Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Session Variables

Options
  • 29-04-2008 3:25pm
    #1
    Registered Users Posts: 11


    Hello,
    I am creating a website using asp which links to a SQL Server database. I want to implement session variables which will take the "username" from the log-in page and display it on the order page which is where the user is directed following a successful log-in.

    At the moment I have the following code written before the first html tag on the log-in page:

    <%session("username") = Request ("username")%>

    and this is the code I have written in the order page to retreive the username, however at the moment nothing is being displayed:

    <%Response.Write Session("username")%>

    Any assistance would be great!


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    What method are you using on your login form? It can be either "get" or "post", for one of the you would use Request("username") to get the value, for the other you would use Request.Form("username") (can't remember which is which). There is also another way which gets it for both methods but can't remember now:o

    On your page with the
    <%session("username") = Request ("username")%>
    put in a temporary
    <%Response.Write Request("username")%>

    aswell, just to make sure you are actually getting the form value back.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Well if it's anything like php, Request would probabaly be it, as it's the catch all after POST and GET in php...

    As I don't know ASP, I can't be sure of the following, but my guess would be that session("username") and Session("username") would be different objects.


  • Registered Users Posts: 11 Redman101


    The login form uses a 'POST' method. Iv tried both variations suggested by stevenmu. Havnt had any joy with either. I have also changed both 'session' objects to be uppercase. I dont understand what is meant by

    "put in a temporary
    <%Response.Write Request("username")%>
    aswell, just to make sure you are actually getting the form value back"

    :confused:


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Try changing this line: <%session("username") = Request ("username")%>

    ..to this: <%session("username") = Request.Form("username")%>


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Case shouldn't matter in classic Asp. Try something like this

    <%session("username") = "foo" %>

    And then see if <%Response.Write Session("username")%> works.

    If it writes "foo" to your page then the problem is with how your handling the request. It it doesn't write foo then the problem lies with your session object.


  • Advertisement
  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Redman101 wrote: »
    The login form uses a 'POST' method. Iv tried both variations suggested by stevenmu. Havnt had any joy with either. I have also changed both 'session' objects to be uppercase. I dont understand what is meant by

    "put in a temporary
    <%Response.Write Request("username")%>
    aswell, just to make sure you are actually getting the form value back"

    :confused:
    It's just to write out what you are getting back from Request("username") to the page, at least that way you will be able to see if Request("username") is returning anything at all. If not then you can work at getting that line right before seeing about putting it into a session variable.

    Also are you sure that "username" is the correct name for your form element? Oh, and that you only have one form element on that page with that name? (I remember spending days tracking down a problem where I'd put in two elements with the same name without realising it :) )


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Is the folder set up as an Application on IIS? If not, Session variables may not persist across different pages. Also, check that there is no underscore in the address of the webserver.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    stevenmu wrote: »
    What method are you using on your login form? It can be either "get" or "post", for one of the you would use Request("username") to get the value, for the other you would use Request.Form("username") (can't remember which is which). There is also another way which gets it for both methods but can't remember now:o

    I think it's Request.Form("val") is for Post, Request.QueryString("val") is for Get and Request("val") is for either.

    OP - having any luck?


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Ah, that sounds right, thanks.


  • Registered Users Posts: 11 Redman101


    Does anyone know if the syntax of the session variables(ie should their be some sort of additional action inserted) changes as the form(on the login page) contains the following action:

    <form action="<%=MM_LoginAction%>" method="POST" name="frm_login" class="freshfast" id="frm_login" >

    this prompts the user to be directed to the welcome page following their login. I have created the session variables with no difficulties in a form which contains no actions using the code from my above post.


  • Advertisement
  • Registered Users Posts: 11 Redman101


    The panick is over!!

    This is the code that I implemented into the page which displays the username:

    <%Response.Write Session.Contents("MM_Username")%>

    Thanks to all for the assistance.


Advertisement