Passing SESSIONS with trans_sid switched off

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

    #1

    Passing SESSIONS with trans_sid switched off

    I want to use sessions to cover myself in case the user switches off cookies
    so I am passing the session ID manually through a hidden input field. This
    is what I have so far.

    index.php page contains:

    <?php

    $_SESSION['entered_userna me'] = "";
    $_SESSION['login'] = "";
    $PHPSESSID = session_id();

    echo "<form method='POST' action='login.p hp'>
    <b>Username:</b>
    <input type='text' name='username' >
    <b>Password:</b>
    <input type='password' name='password' >
    <input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
    <input type='submit' value='Login'>
    </form>";

    ?>

    Now, viewing the source with this page open in the browser, I can see that
    the session ID is in the hidden field. According to the book I'm reading,
    "PHP will automatically get $PHPSESSID without anymore programming from you
    on the login page"
    The part of the next page (login.php) that is processing the login is as
    follows:

    if(mysql_num_ro ws($result) == 1)
    {
    $_SESSION['entered_userna me'] = $_POST['username'];
    $_SESSION['login'] = 'yes';
    header('refresh : 3; url=member.php' );
    echo "<h2><center>Yo u have been validated. Please wait, logging you in. .
    ..</h2><br>
    <center>If your browser doesn't support redirection and you're still here in
    3 seconds, <a href='member.ph p'>click here</a></center>";
    }
    else
    {
    header('refresh : 5; url=index.php') ;
    echo "<b><u><center> Login failure </b></u><br>Username/Password mismatch.
    Sit tight, we're sending you back to the login page in 5 seconds.<br>
    If your browser doesn't support redirection and you're still here in 5
    seconds, <a href='index.php '>click here</a></center>";
    }

    Now we get to the member.php page and the following happens:

    Notice: Undefined index: login in C:\Web\member.p hp on line 10

    Line 10 reads:

    if ($_SESSION['login'] != 'yes')
    {
    echo "<b><u><center> You haven't logged on!</b></u><p>
    <a href='index.php '>Click Here</a> to return to the login page";
    exit();
    }

    This is where it kicks me out. The code on the member.php page is designed
    to stop users doing anything before they log in but unless I can pass the
    session data between pages, the result of the if statement will always be
    false.

    Even more odd is the fact that it works in Internet Explorer and not
    Mozilla. Now I trust Mozilla's standards far more than IE so I really want
    to make it work in Mozilla.

    Sorry this is such a long post, I tried to keep it as short as possible but
    give enough information to make it make sense.

    So what am I missing? And what is IE doing that Moz isn't?

    Thanks for any suggestions.


  • Peter James

    #2
    Re: Passing SESSIONS with trans_sid switched off

    First, rather than manually passing the session id around, just do an
    ini_set() at the beginning of each page...

    ini_set("sessio n.use_cookies", "off");
    ini_set("sessio n.use_trans_sid ", "on");

    This will automagically append the session id to all relative URL's tha it
    can identify, as well as adding it into a hidden form variable for you. You
    don't need to do it manually.

    Second, you're not passing the session id when you redirect. Writing the
    header like that doesn't get rewritten by PHP or your routine. If you are
    not using cookies, you won't have access to the session id on the next page
    (the one you redirect to). Even with trans_sid, you'll have to manually
    include your session id in the header.

    HTH.
    Pete.

    --

    --
    Peter James
    Editor-in-Chief, php|architect Magazine
    petej@phparch.c om

    php|architect
    The Magazine for PHP Professionals
    The site for PHP professionals, Magazine, Training, Books, Conferences



    "Paul" <Paul@here.co m> wrote in message
    news:bhm410$bp7 $1@titan.btinte rnet.com...[color=blue]
    > I want to use sessions to cover myself in case the user switches off[/color]
    cookies[color=blue]
    > so I am passing the session ID manually through a hidden input field. This
    > is what I have so far.
    >
    > index.php page contains:
    >
    > <?php
    >
    > $_SESSION['entered_userna me'] = "";
    > $_SESSION['login'] = "";
    > $PHPSESSID = session_id();
    >
    > echo "<form method='POST' action='login.p hp'>
    > <b>Username:</b>
    > <input type='text' name='username' >
    > <b>Password:</b>
    > <input type='password' name='password' >
    > <input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
    > <input type='submit' value='Login'>
    > </form>";
    >
    > ?>
    >
    > Now, viewing the source with this page open in the browser, I can see that
    > the session ID is in the hidden field. According to the book I'm reading,
    > "PHP will automatically get $PHPSESSID without anymore programming from[/color]
    you[color=blue]
    > on the login page"
    > The part of the next page (login.php) that is processing the login is as
    > follows:
    >
    > if(mysql_num_ro ws($result) == 1)
    > {
    > $_SESSION['entered_userna me'] = $_POST['username'];
    > $_SESSION['login'] = 'yes';
    > header('refresh : 3; url=member.php' );
    > echo "<h2><center>Yo u have been validated. Please wait, logging you in. .
    > .</h2><br>
    > <center>If your browser doesn't support redirection and you're still here[/color]
    in[color=blue]
    > 3 seconds, <a href='member.ph p'>click here</a></center>";
    > }
    > else
    > {
    > header('refresh : 5; url=index.php') ;
    > echo "<b><u><center> Login failure </b></u><br>Username/Password mismatch.
    > Sit tight, we're sending you back to the login page in 5 seconds.<br>
    > If your browser doesn't support redirection and you're still here in 5
    > seconds, <a href='index.php '>click here</a></center>";
    > }
    >
    > Now we get to the member.php page and the following happens:
    >
    > Notice: Undefined index: login in C:\Web\member.p hp on line 10
    >
    > Line 10 reads:
    >
    > if ($_SESSION['login'] != 'yes')
    > {
    > echo "<b><u><center> You haven't logged on!</b></u><p>
    > <a href='index.php '>Click Here</a> to return to the login page";
    > exit();
    > }
    >
    > This is where it kicks me out. The code on the member.php page is designed
    > to stop users doing anything before they log in but unless I can pass the
    > session data between pages, the result of the if statement will always be
    > false.
    >
    > Even more odd is the fact that it works in Internet Explorer and not
    > Mozilla. Now I trust Mozilla's standards far more than IE so I really want
    > to make it work in Mozilla.
    >
    > Sorry this is such a long post, I tried to keep it as short as possible[/color]
    but[color=blue]
    > give enough information to make it make sense.
    >
    > So what am I missing? And what is IE doing that Moz isn't?
    >
    > Thanks for any suggestions.
    >
    >[/color]

    Comment

    • Paul

      #3
      Re: Passing SESSIONS with trans_sid switched off

      I know I'm going to sound stupid now, but could you just clarify what
      exactly is happening here. At the moment, I am using session.auto_st art = 0
      in php.ini. Should I now switch this back to 0?
      And if I add ini_set("sessio n.use_cookies", "off"); and
      ini_set("sessio n.use_trans_sid ", "on"); to the start of each page, does it
      temporary turn on trans_sid for that browsing session?
      Lastly, when you say "This will automagically append the session id to all
      relative URL's that it can identify, as well as adding it into a hidden form
      variable for you", how is the session ID passed then? Where am I defining a
      variable that can be used on the next page? How does it identify "relative
      URLs"? I've only been at this a month so I'm a bit green.

      Thanks for your help.


      "Peter James" <petej@shaman.c a> wrote in message
      news:vjt7rvh5rc ik80@corp.super news.com...[color=blue]
      > First, rather than manually passing the session id around, just do an
      > ini_set() at the beginning of each page...
      >
      > ini_set("sessio n.use_cookies", "off");
      > ini_set("sessio n.use_trans_sid ", "on");
      >
      > This will automagically append the session id to all relative URL's tha it
      > can identify, as well as adding it into a hidden form variable for you.[/color]
      You[color=blue]
      > don't need to do it manually.
      >
      > Second, you're not passing the session id when you redirect. Writing the
      > header like that doesn't get rewritten by PHP or your routine. If you are
      > not using cookies, you won't have access to the session id on the next[/color]
      page[color=blue]
      > (the one you redirect to). Even with trans_sid, you'll have to manually
      > include your session id in the header.
      >
      > HTH.
      > Pete.
      >
      > --
      >
      > --
      > Peter James
      > Editor-in-Chief, php|architect Magazine
      > petej@phparch.c om
      >
      > php|architect
      > The Magazine for PHP Professionals
      > http://www.phparch.com
      >
      >
      > "Paul" <Paul@here.co m> wrote in message
      > news:bhm410$bp7 $1@titan.btinte rnet.com...[color=green]
      > > I want to use sessions to cover myself in case the user switches off[/color]
      > cookies[color=green]
      > > so I am passing the session ID manually through a hidden input field.[/color][/color]
      This[color=blue][color=green]
      > > is what I have so far.
      > >
      > > index.php page contains:
      > >
      > > <?php
      > >
      > > $_SESSION['entered_userna me'] = "";
      > > $_SESSION['login'] = "";
      > > $PHPSESSID = session_id();
      > >
      > > echo "<form method='POST' action='login.p hp'>
      > > <b>Username:</b>
      > > <input type='text' name='username' >
      > > <b>Password:</b>
      > > <input type='password' name='password' >
      > > <input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
      > > <input type='submit' value='Login'>
      > > </form>";
      > >
      > > ?>
      > >
      > > Now, viewing the source with this page open in the browser, I can see[/color][/color]
      that[color=blue][color=green]
      > > the session ID is in the hidden field. According to the book I'm[/color][/color]
      reading,[color=blue][color=green]
      > > "PHP will automatically get $PHPSESSID without anymore programming from[/color]
      > you[color=green]
      > > on the login page"
      > > The part of the next page (login.php) that is processing the login is as
      > > follows:
      > >
      > > if(mysql_num_ro ws($result) == 1)
      > > {
      > > $_SESSION['entered_userna me'] = $_POST['username'];
      > > $_SESSION['login'] = 'yes';
      > > header('refresh : 3; url=member.php' );
      > > echo "<h2><center>Yo u have been validated. Please wait, logging you in.[/color][/color]
      ..[color=blue][color=green]
      > > .</h2><br>
      > > <center>If your browser doesn't support redirection and you're still[/color][/color]
      here[color=blue]
      > in[color=green]
      > > 3 seconds, <a href='member.ph p'>click here</a></center>";
      > > }
      > > else
      > > {
      > > header('refresh : 5; url=index.php') ;
      > > echo "<b><u><center> Login failure </b></u><br>Username/Password[/color][/color]
      mismatch.[color=blue][color=green]
      > > Sit tight, we're sending you back to the login page in 5 seconds.<br>
      > > If your browser doesn't support redirection and you're still here in 5
      > > seconds, <a href='index.php '>click here</a></center>";
      > > }
      > >
      > > Now we get to the member.php page and the following happens:
      > >
      > > Notice: Undefined index: login in C:\Web\member.p hp on line 10
      > >
      > > Line 10 reads:
      > >
      > > if ($_SESSION['login'] != 'yes')
      > > {
      > > echo "<b><u><center> You haven't logged on!</b></u><p>
      > > <a href='index.php '>Click Here</a> to return to the login page";
      > > exit();
      > > }
      > >
      > > This is where it kicks me out. The code on the member.php page is[/color][/color]
      designed[color=blue][color=green]
      > > to stop users doing anything before they log in but unless I can pass[/color][/color]
      the[color=blue][color=green]
      > > session data between pages, the result of the if statement will always[/color][/color]
      be[color=blue][color=green]
      > > false.
      > >
      > > Even more odd is the fact that it works in Internet Explorer and not
      > > Mozilla. Now I trust Mozilla's standards far more than IE so I really[/color][/color]
      want[color=blue][color=green]
      > > to make it work in Mozilla.
      > >
      > > Sorry this is such a long post, I tried to keep it as short as possible[/color]
      > but[color=green]
      > > give enough information to make it make sense.
      > >
      > > So what am I missing? And what is IE doing that Moz isn't?
      > >
      > > Thanks for any suggestions.
      > >
      > >[/color]
      >[/color]


      Comment

      • Peter James

        #4
        Re: Passing SESSIONS with trans_sid switched off

        If you have access to the php.ini file, then set these session.use_coo kies
        and session.use_tra ns_sid values in the php.ini file.

        auto_start means that a session is started every time... it is very common
        to leave this off, and just use session_start() when you need sessions. If
        you use auto_start, you should also set the use_cookies, etc values in the
        php.ini file.

        As far as appending the session id, PHP will handle it all for you. If you
        start a session (either auto_start or session_start() ) and create a form on
        a page that's using trans_sid, and then check your page source in the
        browser, you should see a hidden field called PHPSESSID in your form.. One
        that you _didn't_ add yourself. It's very cool. Relative URL's are
        essentially just URLs that don't have a host in them. http://foo.com is not
        a relative url, but /bar/index.php is.

        If you have trans_sid on, and you submit the above form and start the
        session on the submitted-to page, then all the $_SESSION vars that you set
        on the previous page will be available to you on your submitted-to page.

        Does that clear anything up, or make it cloudier? :-)

        Pete.

        --

        --
        Peter James
        Editor-in-Chief, php|architect Magazine
        petej@phparch.c om

        php|architect
        The Magazine for PHP Professionals
        The site for PHP professionals, Magazine, Training, Books, Conferences



        "Paul" <Paul@here.co m> wrote in message
        news:bhm82m$gvi $1@hercules.bti nternet.com...[color=blue]
        > I know I'm going to sound stupid now, but could you just clarify what
        > exactly is happening here. At the moment, I am using session.auto_st art =[/color]
        0[color=blue]
        > in php.ini. Should I now switch this back to 0?
        > And if I add ini_set("sessio n.use_cookies", "off"); and
        > ini_set("sessio n.use_trans_sid ", "on"); to the start of each page, does it
        > temporary turn on trans_sid for that browsing session?
        > Lastly, when you say "This will automagically append the session id to all
        > relative URL's that it can identify, as well as adding it into a hidden[/color]
        form[color=blue]
        > variable for you", how is the session ID passed then? Where am I defining[/color]
        a[color=blue]
        > variable that can be used on the next page? How does it identify "relative
        > URLs"? I've only been at this a month so I'm a bit green.
        >
        > Thanks for your help.
        >
        >
        > "Peter James" <petej@shaman.c a> wrote in message
        > news:vjt7rvh5rc ik80@corp.super news.com...[color=green]
        > > First, rather than manually passing the session id around, just do an
        > > ini_set() at the beginning of each page...
        > >
        > > ini_set("sessio n.use_cookies", "off");
        > > ini_set("sessio n.use_trans_sid ", "on");
        > >
        > > This will automagically append the session id to all relative URL's tha[/color][/color]
        it[color=blue][color=green]
        > > can identify, as well as adding it into a hidden form variable for you.[/color]
        > You[color=green]
        > > don't need to do it manually.
        > >
        > > Second, you're not passing the session id when you redirect. Writing[/color][/color]
        the[color=blue][color=green]
        > > header like that doesn't get rewritten by PHP or your routine. If you[/color][/color]
        are[color=blue][color=green]
        > > not using cookies, you won't have access to the session id on the next[/color]
        > page[color=green]
        > > (the one you redirect to). Even with trans_sid, you'll have to manually
        > > include your session id in the header.
        > >
        > > HTH.
        > > Pete.
        > >
        > > --
        > >
        > > --
        > > Peter James
        > > Editor-in-Chief, php|architect Magazine
        > > petej@phparch.c om
        > >
        > > php|architect
        > > The Magazine for PHP Professionals
        > > http://www.phparch.com
        > >
        > >
        > > "Paul" <Paul@here.co m> wrote in message
        > > news:bhm410$bp7 $1@titan.btinte rnet.com...[color=darkred]
        > > > I want to use sessions to cover myself in case the user switches off[/color]
        > > cookies[color=darkred]
        > > > so I am passing the session ID manually through a hidden input field.[/color][/color]
        > This[color=green][color=darkred]
        > > > is what I have so far.
        > > >
        > > > index.php page contains:
        > > >
        > > > <?php
        > > >
        > > > $_SESSION['entered_userna me'] = "";
        > > > $_SESSION['login'] = "";
        > > > $PHPSESSID = session_id();
        > > >
        > > > echo "<form method='POST' action='login.p hp'>
        > > > <b>Username:</b>
        > > > <input type='text' name='username' >
        > > > <b>Password:</b>
        > > > <input type='password' name='password' >
        > > > <input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
        > > > <input type='submit' value='Login'>
        > > > </form>";
        > > >
        > > > ?>
        > > >
        > > > Now, viewing the source with this page open in the browser, I can see[/color][/color]
        > that[color=green][color=darkred]
        > > > the session ID is in the hidden field. According to the book I'm[/color][/color]
        > reading,[color=green][color=darkred]
        > > > "PHP will automatically get $PHPSESSID without anymore programming[/color][/color][/color]
        from[color=blue][color=green]
        > > you[color=darkred]
        > > > on the login page"
        > > > The part of the next page (login.php) that is processing the login is[/color][/color][/color]
        as[color=blue][color=green][color=darkred]
        > > > follows:
        > > >
        > > > if(mysql_num_ro ws($result) == 1)
        > > > {
        > > > $_SESSION['entered_userna me'] = $_POST['username'];
        > > > $_SESSION['login'] = 'yes';
        > > > header('refresh : 3; url=member.php' );
        > > > echo "<h2><center>Yo u have been validated. Please wait, logging you[/color][/color][/color]
        in.[color=blue]
        > .[color=green][color=darkred]
        > > > .</h2><br>
        > > > <center>If your browser doesn't support redirection and you're still[/color][/color]
        > here[color=green]
        > > in[color=darkred]
        > > > 3 seconds, <a href='member.ph p'>click here</a></center>";
        > > > }
        > > > else
        > > > {
        > > > header('refresh : 5; url=index.php') ;
        > > > echo "<b><u><center> Login failure </b></u><br>Username/Password[/color][/color]
        > mismatch.[color=green][color=darkred]
        > > > Sit tight, we're sending you back to the login page in 5 seconds.<br>
        > > > If your browser doesn't support redirection and you're still here in 5
        > > > seconds, <a href='index.php '>click here</a></center>";
        > > > }
        > > >
        > > > Now we get to the member.php page and the following happens:
        > > >
        > > > Notice: Undefined index: login in C:\Web\member.p hp on line 10
        > > >
        > > > Line 10 reads:
        > > >
        > > > if ($_SESSION['login'] != 'yes')
        > > > {
        > > > echo "<b><u><center> You haven't logged on!</b></u><p>
        > > > <a href='index.php '>Click Here</a> to return to the login page";
        > > > exit();
        > > > }
        > > >
        > > > This is where it kicks me out. The code on the member.php page is[/color][/color]
        > designed[color=green][color=darkred]
        > > > to stop users doing anything before they log in but unless I can pass[/color][/color]
        > the[color=green][color=darkred]
        > > > session data between pages, the result of the if statement will always[/color][/color]
        > be[color=green][color=darkred]
        > > > false.
        > > >
        > > > Even more odd is the fact that it works in Internet Explorer and not
        > > > Mozilla. Now I trust Mozilla's standards far more than IE so I really[/color][/color]
        > want[color=green][color=darkred]
        > > > to make it work in Mozilla.
        > > >
        > > > Sorry this is such a long post, I tried to keep it as short as[/color][/color][/color]
        possible[color=blue][color=green]
        > > but[color=darkred]
        > > > give enough information to make it make sense.
        > > >
        > > > So what am I missing? And what is IE doing that Moz isn't?
        > > >
        > > > Thanks for any suggestions.
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]

        Comment

        • Peter James

          #5
          Re: Passing SESSIONS with trans_sid switched off

          Shouldn't, unless your host has session.auto_st art on.

          --

          --
          Peter James
          Editor-in-Chief, php|architect Magazine
          petej@phparch.c om

          php|architect
          The Magazine for PHP Professionals
          The site for PHP professionals, Magazine, Training, Books, Conferences



          "Paul" <Paul@here.co m> wrote in message
          news:bhmaet$l1c $1@hercules.bti nternet.com...[color=blue]
          > 1 last question (promise!!) I've just been looking up ini_set at php.net.
          > Thats pretty cool how you can temporarily change php settings. At present[/color]
          I[color=blue]
          > am writing my webpage on my local machine but in time will upload it to my
          > host. My question is, if session.use_coo kies and session.use_tra ns_sid are
          > enabled on the server and I enter ini_set("sessio n.use_cookies", "off");[/color]
          and[color=blue]
          > ini_set("sessio n.use_trans_sid ", "on"); on the top of each of my web[/color]
          pages,[color=blue]
          > will it have any unexpected effects?
          >
          > Thanks again.
          >
          >
          > "Paul" <Paul@here.co m> wrote in message
          > news:bhm9hr$kr5 $1@titan.btinte rnet.com...[color=green]
          > > Thats slightly overcast with a strong chance of some sunshine later :-)
          > > That kinda cleared things up. Time, error and play will help me figure[/color][/color]
          out[color=blue][color=green]
          > > exactly whats happening but I get the jist of it now.
          > >
          > > Thanks for your help.
          > >
          > > "Peter James" <petej@shaman.c a> wrote in message
          > > news:vjt9qo4dip lf8@corp.supern ews.com...[color=darkred]
          > > > If you have access to the php.ini file, then set these[/color][/color]
          > session.use_coo kies[color=green][color=darkred]
          > > > and session.use_tra ns_sid values in the php.ini file.
          > > >
          > > > auto_start means that a session is started every time... it is very[/color][/color]
          > common[color=green][color=darkred]
          > > > to leave this off, and just use session_start() when you need[/color][/color][/color]
          sessions.[color=blue][color=green]
          > > If[color=darkred]
          > > > you use auto_start, you should also set the use_cookies, etc values in[/color][/color]
          > the[color=green][color=darkred]
          > > > php.ini file.
          > > >
          > > > As far as appending the session id, PHP will handle it all for you.[/color][/color][/color]
          If[color=blue][color=green]
          > > you[color=darkred]
          > > > start a session (either auto_start or session_start() ) and create a[/color][/color]
          > form[color=green]
          > > on[color=darkred]
          > > > a page that's using trans_sid, and then check your page source in the
          > > > browser, you should see a hidden field called PHPSESSID in your form..[/color]
          > > One[color=darkred]
          > > > that you _didn't_ add yourself. It's very cool. Relative URL's are
          > > > essentially just URLs that don't have a host in them. http://foo.com[/color][/color][/color]
          is[color=blue][color=green]
          > > not[color=darkred]
          > > > a relative url, but /bar/index.php is.
          > > >
          > > > If you have trans_sid on, and you submit the above form and start the
          > > > session on the submitted-to page, then all the $_SESSION vars that[/color][/color][/color]
          you[color=blue][color=green]
          > > set[color=darkred]
          > > > on the previous page will be available to you on your submitted-to[/color][/color][/color]
          page.[color=blue][color=green][color=darkred]
          > > >
          > > > Does that clear anything up, or make it cloudier? :-)
          > > >
          > > > Pete.
          > > >
          > > > --
          > > >
          > > > --
          > > > Peter James
          > > > Editor-in-Chief, php|architect Magazine
          > > > petej@phparch.c om
          > > >
          > > > php|architect
          > > > The Magazine for PHP Professionals
          > > > http://www.phparch.com
          > > >
          > > >
          > > > "Paul" <Paul@here.co m> wrote in message
          > > > news:bhm82m$gvi $1@hercules.bti nternet.com...
          > > > > I know I'm going to sound stupid now, but could you just clarify[/color][/color][/color]
          what[color=blue][color=green][color=darkred]
          > > > > exactly is happening here. At the moment, I am using[/color][/color]
          > session.auto_st art[color=green]
          > > =[color=darkred]
          > > > 0
          > > > > in php.ini. Should I now switch this back to 0?
          > > > > And if I add ini_set("sessio n.use_cookies", "off"); and
          > > > > ini_set("sessio n.use_trans_sid ", "on"); to the start of each page,[/color][/color]
          > does[color=green]
          > > it[color=darkred]
          > > > > temporary turn on trans_sid for that browsing session?
          > > > > Lastly, when you say "This will automagically append the session id[/color][/color][/color]
          to[color=blue][color=green]
          > > all[color=darkred]
          > > > > relative URL's that it can identify, as well as adding it into a[/color][/color]
          > hidden[color=green][color=darkred]
          > > > form
          > > > > variable for you", how is the session ID passed then? Where am I[/color]
          > > defining[color=darkred]
          > > > a
          > > > > variable that can be used on the next page? How does it identify[/color]
          > > "relative[color=darkred]
          > > > > URLs"? I've only been at this a month so I'm a bit green.
          > > > >
          > > > > Thanks for your help.
          > > > >
          > > > >
          > > > > "Peter James" <petej@shaman.c a> wrote in message
          > > > > news:vjt7rvh5rc ik80@corp.super news.com...
          > > > > > First, rather than manually passing the session id around, just do[/color][/color]
          > an[color=green][color=darkred]
          > > > > > ini_set() at the beginning of each page...
          > > > > >
          > > > > > ini_set("sessio n.use_cookies", "off");
          > > > > > ini_set("sessio n.use_trans_sid ", "on");
          > > > > >
          > > > > > This will automagically append the session id to all relative[/color][/color][/color]
          URL's[color=blue][color=green]
          > > tha[color=darkred]
          > > > it
          > > > > > can identify, as well as adding it into a hidden form variable for[/color]
          > > you.[color=darkred]
          > > > > You
          > > > > > don't need to do it manually.
          > > > > >
          > > > > > Second, you're not passing the session id when you redirect.[/color][/color]
          > Writing[color=green][color=darkred]
          > > > the
          > > > > > header like that doesn't get rewritten by PHP or your routine. If[/color][/color]
          > you[color=green][color=darkred]
          > > > are
          > > > > > not using cookies, you won't have access to the session id on the[/color][/color]
          > next[color=green][color=darkred]
          > > > > page
          > > > > > (the one you redirect to). Even with trans_sid, you'll have to[/color]
          > > manually[color=darkred]
          > > > > > include your session id in the header.
          > > > > >
          > > > > > HTH.
          > > > > > Pete.
          > > > > >
          > > > > > --
          > > > > >
          > > > > > --
          > > > > > Peter James
          > > > > > Editor-in-Chief, php|architect Magazine
          > > > > > petej@phparch.c om
          > > > > >
          > > > > > php|architect
          > > > > > The Magazine for PHP Professionals
          > > > > > http://www.phparch.com
          > > > > >
          > > > > >
          > > > > > "Paul" <Paul@here.co m> wrote in message
          > > > > > news:bhm410$bp7 $1@titan.btinte rnet.com...
          > > > > > > I want to use sessions to cover myself in case the user switches[/color][/color]
          > off[color=green][color=darkred]
          > > > > > cookies
          > > > > > > so I am passing the session ID manually through a hidden input[/color]
          > > field.[color=darkred]
          > > > > This
          > > > > > > is what I have so far.
          > > > > > >
          > > > > > > index.php page contains:
          > > > > > >
          > > > > > > <?php
          > > > > > >
          > > > > > > $_SESSION['entered_userna me'] = "";
          > > > > > > $_SESSION['login'] = "";
          > > > > > > $PHPSESSID = session_id();
          > > > > > >
          > > > > > > echo "<form method='POST' action='login.p hp'>
          > > > > > > <b>Username:</b>
          > > > > > > <input type='text' name='username' >
          > > > > > > <b>Password:</b>
          > > > > > > <input type='password' name='password' >
          > > > > > > <input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
          > > > > > > <input type='submit' value='Login'>
          > > > > > > </form>";
          > > > > > >
          > > > > > > ?>
          > > > > > >
          > > > > > > Now, viewing the source with this page open in the browser, I[/color][/color][/color]
          can[color=blue][color=green]
          > > see[color=darkred]
          > > > > that
          > > > > > > the session ID is in the hidden field. According to the book I'm
          > > > > reading,
          > > > > > > "PHP will automatically get $PHPSESSID without anymore[/color][/color][/color]
          programming[color=blue][color=green][color=darkred]
          > > > from
          > > > > > you
          > > > > > > on the login page"
          > > > > > > The part of the next page (login.php) that is processing the[/color][/color][/color]
          login[color=blue][color=green]
          > > is[color=darkred]
          > > > as
          > > > > > > follows:
          > > > > > >
          > > > > > > if(mysql_num_ro ws($result) == 1)
          > > > > > > {
          > > > > > > $_SESSION['entered_userna me'] = $_POST['username'];
          > > > > > > $_SESSION['login'] = 'yes';
          > > > > > > header('refresh : 3; url=member.php' );
          > > > > > > echo "<h2><center>Yo u have been validated. Please wait, logging[/color][/color]
          > you[color=green][color=darkred]
          > > > in.
          > > > > .
          > > > > > > .</h2><br>
          > > > > > > <center>If your browser doesn't support redirection and you're[/color][/color]
          > still[color=green][color=darkred]
          > > > > here
          > > > > > in
          > > > > > > 3 seconds, <a href='member.ph p'>click here</a></center>";
          > > > > > > }
          > > > > > > else
          > > > > > > {
          > > > > > > header('refresh : 5; url=index.php') ;
          > > > > > > echo "<b><u><center> Login failure </b></u><br>Username/Password
          > > > > mismatch.
          > > > > > > Sit tight, we're sending you back to the login page in 5[/color]
          > > seconds.<br>[color=darkred]
          > > > > > > If your browser doesn't support redirection and you're still[/color][/color][/color]
          here[color=blue]
          > in[color=green]
          > > 5[color=darkred]
          > > > > > > seconds, <a href='index.php '>click here</a></center>";
          > > > > > > }
          > > > > > >
          > > > > > > Now we get to the member.php page and the following happens:
          > > > > > >
          > > > > > > Notice: Undefined index: login in C:\Web\member.p hp on line 10
          > > > > > >
          > > > > > > Line 10 reads:
          > > > > > >
          > > > > > > if ($_SESSION['login'] != 'yes')
          > > > > > > {
          > > > > > > echo "<b><u><center> You haven't logged on!</b></u><p>
          > > > > > > <a href='index.php '>Click Here</a> to return to the login page";
          > > > > > > exit();
          > > > > > > }
          > > > > > >
          > > > > > > This is where it kicks me out. The code on the member.php page[/color][/color][/color]
          is[color=blue][color=green][color=darkred]
          > > > > designed
          > > > > > > to stop users doing anything before they log in but unless I can[/color]
          > > pass[color=darkred]
          > > > > the
          > > > > > > session data between pages, the result of the if statement will[/color]
          > > always[color=darkred]
          > > > > be
          > > > > > > false.
          > > > > > >
          > > > > > > Even more odd is the fact that it works in Internet Explorer and[/color][/color]
          > not[color=green][color=darkred]
          > > > > > > Mozilla. Now I trust Mozilla's standards far more than IE so I[/color]
          > > really[color=darkred]
          > > > > want
          > > > > > > to make it work in Mozilla.
          > > > > > >
          > > > > > > Sorry this is such a long post, I tried to keep it as short as
          > > > possible
          > > > > > but
          > > > > > > give enough information to make it make sense.
          > > > > > >
          > > > > > > So what am I missing? And what is IE doing that Moz isn't?
          > > > > > >
          > > > > > > Thanks for any suggestions.
          > > > > > >
          > > > > > >
          > > > > >
          > > > >
          > > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]

          Comment

          • Paul

            #6
            Re: Passing SESSIONS with trans_sid switched off

            I have set session.use_tra ns_sid = 1 and session.use_coo kies = 1 as
            suggested. My index.php now looks like this:

            <html>
            <head>
            <title>Welcom e</title>
            <meta http-equiv="Content-Type" content="text/html;
            charset=iso-8859-1"></head>
            <?php
            session_start() ;
            $_SESSION['entered_userna me'] = "";
            $_SESSION['login'] = "";

            echo "<form method='POST' action='login.p hp'>
            <p
            align='center'> &nbsp;&nbsp;&nb sp;<b>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb s
            p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;
            <font size='2'>
            Username:&nbsp; </font></b>
            <font size='2'>
            <input type='text' name='username' size='13' style='height: 20'>
            &nbsp;&nbsp;<b> Password:&nbsp; &nbsp;</b>
            <input type='password' name='password' size='13' style='height: 20'>
            &nbsp;
            <input type='submit' value='Login'></font>
            &nbsp;
            <font size='2'><b>Not a member?</b> Sign up <a
            href='register. html'>here</a></font>
            <p align='center'> <font size='2'><b>For gotten your password?</b> <a
            href='password_ reminder.php'>C lick
            here</a> to have it e-mailed to you. </font>
            </form>";

            ?>
            <H1>Header 1</H1>
            <H2>Text about something</H2>

            Viewing the source of the page I don't see a hidden field with the SID in it
            (see below). What am I doing wrong?

            <html>
            <head>
            <title>Welcom e</title>
            <meta http-equiv="Content-Type" content="text/html;
            charset=iso-8859-1"></head>
            <form method='POST' action='login.p hp'>
            <p
            align='center'> &nbsp;&nbsp;&nb sp;<b>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb s
            p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;
            <font size='2'>
            Username:&nbsp; </font></b>
            <font size='2'>
            <input type='text' name='username' size='13' style='height: 20'>
            &nbsp;&nbsp;<b> Password:&nbsp; &nbsp;</b>
            <input type='password' name='password' size='13' style='height: 20'>
            &nbsp;
            <input type='submit' value='Login'></font>
            &nbsp;
            <font size='2'><b>Not a member?</b> Sign up <a
            href='register. html'>here</a></font>
            <p align='center'> <font size='2'><b>For gotten your password?</b> <a
            href='password_ reminder.php'>C lick
            here</a> to have it e-mailed to you. </font>
            </form>/n<H1>Header 1</H1>
            <H2>Text about something</H2>
            </body>
            </html>


            Comment

            Working...