Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    Hong Kong
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Session and Register Global off in PHP 4.3.0

    Hi,

    I am developing web with PHP 4.3.0 under win2k environment. I set register_globals = off.

    Now I have two simple pages.

    ====Session.php=======
    <?
    $_SESSION["user_name"] = "michael" ;

    if (isset($_SESSION["user_name"]))
    {
    echo "User name:" . $_SESSION["user_name"] ;
    }
    else
    {
    echo "User name not set." ;
    }
    ?>

    ====Session2.php=======
    <?
    if (isset($_SESSION["user_name"]))
    {
    echo "User name:" . $_SESSION["user_name"] ;
    }
    else
    {
    echo "User name not set." ;
    }
    ?>

    I visit session.php, then session2.php.

    I got "User name:michael" in session.php but "User name not set." in session2.php.

    I expect the $_SESSION["user_name"] should be available in both pages...

    What's the problem?

    Thanks in advance.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    That's not quite how sessions work in PHP. Here is a tutorial that explains the use of sessions:

    http://hotwired.lycos.com/webmonkey/...tw=programming
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    those are very OLD tutorials spooks, too old for reg_globals = off

    session_register is now defunct

    hkucsus - you session calls are fine - exactly the same as I use in PHP4.2.3 with one exception

    start every (I mean every) script with

    session_start();

    If that doesn't do the trick, check your session support in php.ini or php info
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You got something against things that are old? Yeah ok time to update my list of bookmarks. lol Here is a more current one:

    http://www.free2code.net/tutorials/o...0/sessions.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    Hong Kong
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks you guys.

    Problem solved -- I missed 'session_start()'.


  •  

    Posting Permissions

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