[PHP] Session handling problems

Discussion in 'Web Design & Coding' started by Glaanieboy, Jan 3, 2004.

  1. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    According to many PHP manuals on the net, this should work:

    Code:
    session_start();
    
    $user = $_GET['user'];
    session_register("user");
    
    print $user;
    
    What I want to do, is first get $user (with $_GET) from the address line with session.php?user=Glaanieboy. Next I want to register $user to the current session, so the variable $user will still contain the value of "Glaanieboy", just like session were invented for. But for some reason, this above code won't work.
    It works when I use ?user=Glaanieboy, but when I leave the ?(etc) bit away, it prints nothing. Why? I have registered $user, right?
    I remember doing this ages ago, but unfortunately I deleted the files in question.
     
  2. Jason2k1

    Jason2k1 Guest

    I think the following will do what you want:
    PHP:
    <?php
    session_start
    ();

    if (isset(
    $_SESSION['user'])){

    $user $_SESSION['user'];

    }else{

    $_SESSION['user'] = $_GET['user'];

    $user $_GET['user'];
    }

    print 
    $user;
    ?>
     
  3. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Thank you very much :)