problem with sessions

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

    #1

    problem with sessions

    i have a problem. i can create session variables, but i can't access
    them across pages.

    for example.

    page2.php

    Code:

    <?php
    // start the session
    session_start() ;
    header("Cache-control: private"); //IE 6 Fix

    echo "<strong>St ep 2 - Register Session </strong><br />";

    // Get the user's input from the form
    $name = $_POST['name'];

    // Register session key with the value
    $_SESSION['name'] = $name;

    // Display the sssion information:
    ?>

    Welcome to my website <strong><? echo $_SESSION['name'];
    ?></strong>!<br />
    Let's see what happens on the <a href="page3.php ">next page.</a><br
    /><br />



    page3.php
    Code:

    <?php
    // start the session
    session_start() ;
    header("Cache-control: private"); //IE 6 Fix
    ?>
    <strong>Step 3 - test Session Part II </strong><br />
    Hey <strong><? echo $_SESSION['name']; ?></strong> Everything is still
    working!<br /><br />
    <strong>Pick an option:</strong><br />
    Let's delete this session value now. <a href="page4.php ">Click
    Here.</a><br />
    Let's destroy this session. <a href="page5.php ">Click Here.</a><br
    /><br />




    on page2.php (after the _SESSION['name'] variable is set with a form
    on another page) the value of the variable comes up fine. however on
    page3.php, the value is blank. any thoughts why? i tried tinkering
    with the php.ini (v.4.0 on a Win98 box) but nothing changed.

    thanks in advance
  • Agelmar

    #2
    Re: problem with sessions

    The most probable thing is that there is a problem in your configuration
    file, namely session.save_pa th. This must be set to something that is
    writable by your webserver. By default it is set to /tmp, which does not
    exist on a windows box...

    If this is not the problem, try setting error_reporting = E_ALL, this may
    expose some other error...

    Also, I hope you don't mean you're using php 4.0, because $_SESSION does not
    exist until 4.1.0.

    // Ian Fette
    // Proponent, comp.lang.php

    chris jamison wrote:[color=blue]
    > i have a problem. i can create session variables, but i can't access
    > them across pages.
    >
    > for example.
    >
    > page2.php
    >
    > Code:
    >
    > <?php
    > // start the session
    > session_start() ;
    > header("Cache-control: private"); //IE 6 Fix
    >
    > echo "<strong>St ep 2 - Register Session </strong><br />";
    >
    > // Get the user's input from the form
    > $name = $_POST['name'];
    >
    > // Register session key with the value
    > $_SESSION['name'] = $name;
    >
    > // Display the sssion information:[color=green]
    >>[/color]
    >
    > Welcome to my website <strong><? echo $_SESSION['name'];[color=green]
    >> </strong>!<br />[/color]
    > Let's see what happens on the <a href="page3.php ">next page.</a><br
    > /><br />
    >
    >
    >
    > page3.php
    > Code:
    >
    > <?php
    > // start the session
    > session_start() ;
    > header("Cache-control: private"); //IE 6 Fix[color=green]
    >>[/color]
    > <strong>Step 3 - test Session Part II </strong><br />
    > Hey <strong><? echo $_SESSION['name']; ?></strong> Everything is still
    > working!<br /><br />
    > <strong>Pick an option:</strong><br />
    > Let's delete this session value now. <a href="page4.php ">Click
    > Here.</a><br />
    > Let's destroy this session. <a href="page5.php ">Click Here.</a><br
    > /><br />
    >
    >
    >
    >
    > on page2.php (after the _SESSION['name'] variable is set with a form
    > on another page) the value of the variable comes up fine. however on
    > page3.php, the value is blank. any thoughts why? i tried tinkering
    > with the php.ini (v.4.0 on a Win98 box) but nothing changed.
    >
    > thanks in advance[/color]


    Comment

    • NixoiD

      #3
      Re: problem with sessions

      On 26 Dec 2003 19:43:14 -0800, chris jamison <obsidianchrysa lis@yahoo.com>
      wrote:
      maybe "global $_SESSION;" ?
      --
      --
      NixoiD || nixoid@km.ru || #xakep@icr.wene t.ru
      --
      Window$ for Desktop? LOL!..
      Using M2 on Slackware 9.1

      Comment

      • Agelmar

        #4
        Re: problem with sessions

        NixoiD wrote:[color=blue]
        > On 26 Dec 2003 19:43:14 -0800, chris jamison
        > <obsidianchrysa lis@yahoo.com> wrote:
        > maybe "global $_SESSION;" ?[/color]

        $_SESSION is a superglobal. It is global no matter what its context.


        Comment

        • Dave Richards

          #5
          Re: problem with sessions

          On Fri, 26 Dec 2003 19:43:14 -0800, chris jamison wrote:
          [color=blue]
          > i have a problem. i can create session variables, but i can't access
          > them across pages.
          >[/color]

          could be that you're not passing your session id to the browser or a
          problem with your php.ini file.

          Dave

          Comment

          • The Plankmeister

            #6
            Re: problem with sessions

            > on page2.php (after the _SESSION['name'] variable is set with a form[color=blue]
            > on another page) the value of the variable comes up fine. however on
            > page3.php, the value is blank. any thoughts why? i tried tinkering
            > with the php.ini (v.4.0 on a Win98 box) but nothing changed.
            >
            > thanks in advance[/color]

            You could try finding out exactly where it's putting your session files.
            Then keep that folder window open while you browse around your
            session-testing pages to see if the session file stays put. Perhaps your
            session.gc_prob ability is set to 100 and your session.gc_maxl ifetime is set
            to something very low (1 or 2) This scenario (I think) would match your
            description of what's happening. However, it is very unlikely.
            But if you can see that your session files are present but aren't 'seen' by
            the system, then... erm... Dunno. :)

            HTH.

            Plankmeister


            Comment

            Working...