Passing querystring variable throughtout site?

Discussion in 'PHP' started by ridesign, Feb 22, 2009.

  1. #1
    Currently I have a variable which comes via the query string like:

    http://www.domain.com/?id=123

    and on the homepage I can access this variable using $_GET['id'], but if I click on any page on the website I can not access this variable anymore, is there a way so that I can access this variable where ever I go on my website?
     
    ridesign, Feb 22, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    What's your url structure ( home.php or index.php?page=home ) ? There are only 2 options to save it - start a session or store it in cookie ..

    index.php?id=15
    <?php
    // Start a new session
    session_start();
    // Assign our id to the current session
    $_SESSION['id'] = $_GET['id'];
    ?>
    PHP:
    home.php ( no variable as you can see )
    <?php
    // Open session
    session_start();
    // Get our ID
    $id = $_SESSION['id'];
    // Print it out or do whatever you want with it
    echo "ID was : ".$id;
    ?>
    PHP:
     
    ActiveFrost, Feb 22, 2009 IP
    wisdomtool likes this.
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You can use session or cookie to pass the info like ActiveFrost said.

    Session is just for the current session and will be destroyed once the browser is closed.

    Cookie can be stored for as long as you want (you decide), but will be destroyed if the user clears cookie.

    - ads2help
     
    ads2help, Feb 22, 2009 IP