PHP Session Question

Discussion in 'PHP' started by simacaj, Dec 17, 2009.

  1. #1
    Hey Everyone -

    I have a question about PHP Sessions.

    within my code, I am trying to get a value from a URL parameter and store it in a session.

    <?php
    
    //get event value from URL
    $event = $_GET['event'];
    
    //Start Session and set it equal to parameter
    session_start();
    $_SESSION['event'] = $event;
    ?>
    
    PHP:
    I want to get the value from the session on another page and use it in my logic.

    <?php echo "event value = ". $_SESSION['event']; ?>
    PHP:
    I am not getting any value from the session value. The code displays "event value = ". Am I doing something wrong?

    Thanks
     
    simacaj, Dec 17, 2009 IP
  2. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #2
    Does the other page have session_start(); at the top of it?
     
    CoreyPeerFly, Dec 17, 2009 IP
  3. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #3
    On the second page you need to have the session_start(); on top of it. If it does I would try displaying it on the page where it was set and go from there.
     
    Pudge1, Dec 17, 2009 IP
  4. simacaj

    simacaj Peon

    Messages:
    142
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Guys....I tried adding session_start() to the second page and I still have the same problem.

    On the first page I am setting the session value then redirecting to a new page with header ();

    
    header("Location: http://www.myurl.com/parent_signup.php");
    
    PHP:
    Does that have anything to do with it?

    Thanks
     
    simacaj, Dec 17, 2009 IP
  5. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #5
    That shouldn't have any thing to do with it. I just tested it with a header redirect and it worked fine.
     
    CoreyPeerFly, Dec 17, 2009 IP
  6. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #6
    Try these

    one.php
    
    <?php
    session_start();
    
    $_SESSION['fruit'] = 'apple';
    
    header('Location: two.php');
    ?>
    
    PHP:
    two.php
    
    <?php
    session_start();
    
    var_dump($_SESSION['fruit']);
    ?>
    
    PHP:
     
    xrvel, Dec 18, 2009 IP
  7. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    the session_start();
    must be in the first line in the first file
     
    astkboy2008, Dec 18, 2009 IP