PHP not carrying Session variables on next page

Discussion in 'PHP' started by greatlogix, Dec 5, 2008.

  1. #1
    PHP is carrying few session variables on next page and leaving few. Following are the 3 session variables i am trying to access on "confirm_cart.php" after redirect. I am getting session values of those variables which are in include file only. print_r($_SESSION) is not printing session variables defined in foo.php



    
    <? 
    // file name: foo.php
    ob_start();
    include "include/open_session.php";
    @extract($_POST);
     $_SESSION['txtFName'] = $txtFName;
     $_SESSION['txtLName'] = $txtLName;
      $_SESSION['sEmail'] = $sEmail;     
    // print_r($_SESSION); exit();              
     header ("Location: confirm_cart.php");
      ob_end_flush();
    ?>
    PHP:
    include file(open_session.php) contents:
    <? session_start();
    
    		if(empty($_SESSION['sess_id']) || !isset($_SESSION['sess_id'])){
    			$sess_id = session_id();
    			$_SESSION['sess_logedin'] = 0;
    			$_SESSION['sess_id'] = $sess_id;
    			$_SESSION['customer_session_id'] = 0;
    		} 
    ?>
    PHP:
    Help me please to solve this issue.
     
    greatlogix, Dec 5, 2008 IP
  2. sandstorm140

    sandstorm140 Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Make sure you have session_start(); on top of each page
     
    sandstorm140, Dec 5, 2008 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    yes session_start(); is on top of confirm_cart.php

    In fact same include file on top of the confirm_cart.php
    include "include/open_session.php";
    this file has session_start(); at first line.

    contents of confirm_cart.php
    
    include "include/open_session.php";
     print_r($_SESSION); // I,m not getting all session variables here
    //..... more code....
    
    PHP:
     
    greatlogix, Dec 5, 2008 IP
  4. t33mya

    t33mya Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Make sure there is no output rendered in any included file and session_start() is not called under any condition.

    Better write error_reporting(E_ALL); at the top of each script to know what the notice/warning its throwing.
     
    t33mya, Dec 5, 2008 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    Off the top of my head, I would presume that your output buffering is messing up the session. Try starting the session before ob_start.
     
    jestep, Dec 5, 2008 IP
  6. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #6
    No its not the problem. I have tested.
     
    greatlogix, Dec 6, 2008 IP
  7. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #7
    I ran your code in my local server and got this as the output.
    
    Array
    (
        [sess_logedin] => 0
        [sess_id] => ceb9c6ade63363af681d395db864fd8d
        [customer_session_id] => 0
        [txtFName] => 
        [txtLName] => 
        [sEmail] => 
    )
    
    PHP:
    Its working here.
     
    xrvel, Dec 6, 2008 IP
  8. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #8
    Thanks xrvel for your time and effort. Thats my problem i am not getting txtFName, txtLName and sEmail on the next page.

    Array
    (
    [sess_logedin] => 0
    [sess_id] => ceb9c6ade63363af681d395db864fd8d
    [customer_session_id] => 0

    )

    I am getting only this. Is there something to do with Server/php.ini settings?
     
    greatlogix, Dec 6, 2008 IP
  9. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #9
    What about this :
    1. Checking your $_POST with
      print_r($_POST);
      PHP:
      .
      If you see the data there,
    2. check the $txtFName with
      var_dump($txtFName);
      PHP:
     
    xrvel, Dec 6, 2008 IP