www.webdeveloper.com
Results 1 to 7 of 7

Thread: Sessions

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Posts
    18

    Question Sessions

    Perhaps I don't quite understand sessions yet... but why does this code always output: "0Page" ??? Thanks in advance.

    PHP Code:
    <?php
    session_start
    ();
    // Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
    if (!isset($_SESSION['count'])) {
        
    $_SESSION['count'] = 0;
    } else {
        
    $_SESSION['count']++;
    }
    echo 
    $_SESSION['count'];
    echo 
    "<a href=\"stest.php\">Page</a>";
    ?>
    Also: I got this from the PHP.net site, so.... why does it not work?

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    If you look at the logic in the code, it is like this. It starts the session, checks to see if the variable $_SESSION['count'] has a value. If it does, it changes the variable ($_SESSION['count']) to equal zero, if it doesn't, the variable $_SESSION['count'] will increment (meaning if it was 0, it will be 1, if it was 1, it will be 2, etc.). Then it writes to the page the variable's value, and a link to "stest.php." Now then, you'll realize that you have no <br> tag in there, so the variable will be written right along side of the link. Also, in this function, unless the session variable "$count" has a value, it will become zero. Therefore, try putting ?count=1 at the end of your page and re-running the script. Then test the results.

    I've never used sessions before, but this is just what it looks like to me..


    Jona

  3. #3
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Wait, take off all of that. The code works better than you know. Run the code and click the link. Each time the number will increment.

    Jona

  4. #4
    Join Date
    Mar 2003
    Posts
    18
    That's weird. I click the link and it stays at zero.
    Are there any PHP settings in the php.ini file (or elsewhere) that could effect this?

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Go back and look at the page that gave you that code.

    Jona

  6. #6
    Join Date
    Mar 2003
    Posts
    18
    Fixed! I went through the php.ini stuff for sessions, reading all the comments in the file, and finally found it: session.save_path. I set that to a folder, and it works!

  7. #7
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Great!

    Jona

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles