session variable problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • farooqazeem

    session variable problem

    Hi guys,

    I’m facing some problem can u solve it.

    Problem is:
    I’m giving user Id and password in (Login_sess.asp ) and submit it to page
    (sess_test.asp) . I am setting session variable (session(“Sin ”)=”Yes”) just
    before redirecting to the same page, but in first time I do not received the
    value of session variable when I redirect it, when I execute this process
    second time or redirect it only with the page name (sess_test.asp) it
    receives session value.

    Can you tell me what’s the problem?
    I’ve to receive session value in first time and have to redirect with
    compete URL


    Login_sess.asp (Page is)

    <%@ Language=VBScri pt %>
    <html><head>
    <title>Login </title>
    </head>
    <h1 align=center>Lo gin in Your Account </h1>
    <BODY>
    <form name=login method=post action=sess_tes t.asp >
    <table width=40%>
    <tr><td colspan=2>Type Your ID and Password</td></tr>
    <tr><td>Enter Your ID</td><td><INPUT type="text" id=txtUID name=txtUID[color=blue]
    ></td></tr>[/color]
    <tr><td>Passwor d </td><td><INPUT type="text" id=txtPwd name=txtPwd ></td></tr>
    </table>

    <table width=40%><tr>< td align=center><I NPUT type="submit" value="Submit"
    id=submit name=submit>
    &nbsp&nbsp <INPUT type="reset" value="Reset" id=reset name=reset >
    </td></table>
    </form></BODY></HTML>


    Sess_test.asp (file is)
    <%@ Language=VBScri pt %>
    <html><head><ti tle>Main Page </title></head>
    <body><form method=get>
    <%Response.Writ e "session Variable =" & Session("Sin")
    if Request("txtUID ") <> "" then
    Session("Sin")= "Yes"
    Response.Redire ct "http://localhost/sg/sess_test.asp"
    'Response.Redir ect "sess_tes.a sp"
    end if %>
    <br><A href="Login_ses s.asp">Sin In</A>
    </body></form>
    </HTML>



    regards,
    farooq











  • Cowboy (Gregory A. Beamer) - MVP

    #2
    RE: session variable problem

    Until you redirect, you cannot grab the session variable, as it is set in a
    session (server) cookie and sent to the client. Once you do the
    Response.Redire ct, the cookie value is sent with the Request. Then, you can
    get it.

    I am not sure what you are trying to do architecturally , however. If you
    want to check if a user is logged in (able to surf pages), create an include
    ..asp file with the

    if not Session("Sin") = "Yes" then
    'Redirect to login
    End If

    This forces every page to redirect to logon until user is logged in (or
    every page with the include). Avoid this script on the login pages.

    Hope this makes sense.

    ---

    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************** ************
    Think Outside the Box!
    *************** ************

    "farooqazee m" wrote:
    [color=blue]
    > Hi guys,
    >
    > I’m facing some problem can u solve it.
    >
    > Problem is:
    > I’m giving user Id and password in (Login_sess.asp ) and submit it to page
    > (sess_test.asp) . I am setting session variable (session(“Sin ”)=”Yes”) just
    > before redirecting to the same page, but in first time I do not received the
    > value of session variable when I redirect it, when I execute this process
    > second time or redirect it only with the page name (sess_test.asp) it
    > receives session value.
    >
    > Can you tell me what’s the problem?
    > I’ve to receive session value in first time and have to redirect with
    > compete URL
    >
    >
    > Login_sess.asp (Page is)
    >
    > <%@ Language=VBScri pt %>
    > <html><head>
    > <title>Login </title>
    > </head>
    > <h1 align=center>Lo gin in Your Account </h1>
    > <BODY>
    > <form name=login method=post action=sess_tes t.asp >
    > <table width=40%>
    > <tr><td colspan=2>Type Your ID and Password</td></tr>
    > <tr><td>Enter Your ID</td><td><INPUT type="text" id=txtUID name=txtUID[color=green]
    > ></td></tr>[/color]
    > <tr><td>Passwor d </td><td><INPUT type="text" id=txtPwd name=txtPwd ></td></tr>
    > </table>
    >
    > <table width=40%><tr>< td align=center><I NPUT type="submit" value="Submit"
    > id=submit name=submit>
    > <INPUT type="reset" value="Reset" id=reset name=reset >
    > </td></table>
    > </form></BODY></HTML>
    >
    >
    > Sess_test.asp (file is)
    > <%@ Language=VBScri pt %>
    > <html><head><ti tle>Main Page </title></head>
    > <body><form method=get>
    > <%Response.Writ e "session Variable =" & Session("Sin")
    > if Request("txtUID ") <> "" then
    > Session("Sin")= "Yes"
    > Response.Redire ct "http://localhost/sg/sess_test.asp"
    > 'Response.Redir ect "sess_tes.a sp"
    > end if %>
    > <br><A href="Login_ses s.asp">Sin In</A>
    > </body></form>
    > </HTML>
    >
    >
    >
    > regards,
    > farooq
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >[/color]

    Comment

    Working...