Need help in session_register()

Discussion in 'PHP' started by jbashir, Sep 20, 2007.

  1. #1
    hi

    I have registered session in "page1.php" as

    session_start();
    session_register('client_id', $client_id);
    session_register('client_name', $client_name);

    How can I access these values in the other page "page2.php". I have tried as:
    session_start();
    if(session_is_registered('client_id')){
    echo $client_id;
    }
    but no result is displayed. But when I include "page1.php" in "page2.php" as
    include "page1.php";
    then I can access it. Does it mean that I have to include "page1.php" in all pages of my application? Any solution please.

    Thanks

    Joseph
     
    jbashir, Sep 20, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Something tells me you are going about what you are doing the wrong way.

    Anyway, your script is relying on register_globals which may be disabled and is also using deprecated functions, here is the way to do it:

    page1:

    session_start();
    $_SESSION['client_id'] = $client_id;
    $_SESSION['client_name'] = $client_name;

    page 2:

    session_start();
    echo $_SESSION['client_id'];
     
    krt, Sep 20, 2007 IP
  3. jbashir

    jbashir Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    register_globals is Enabled but still there was problem. By deprecated functions, do you mean that they are no more functional? The application was running without any problem few months back, and I am still using the same PHP version and Apache version.

    Anyhow, If I do it the way you suggests, then how would I check:

    if(session_is_registered('client_id')){
    }

    Please help, I am new in PHP.
     
    jbashir, Sep 20, 2007 IP
  4. best host world

    best host world Peon

    Messages:
    213
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi , Whats your Php Version ?
     
    best host world, Sep 20, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    besthostworld, please use default fonts and colours, it looks ugly otherwise. :p

    jbashir, the equivalent to if(session_is_registered('client_id')) is:
    if (isset($_SESSION['client_id']))

    And by deprecated, I mean they are not recommended to be used and may be omitted from later PHP versions.
     
    krt, Sep 20, 2007 IP
  6. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Will be omitted in this case. register_globals will be completely removed in php 6.0; the concept will no longer exist.
     
    sea otter, Sep 20, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    I was generalising, but yes, you are right. Along with magic quotes too, good riddance :)
     
    krt, Sep 20, 2007 IP
  8. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah, I know you know. I was driving the point home for the OP :)
     
    sea otter, Sep 21, 2007 IP