Results 1 to 3 of 3

Thread: Weird PHP Session variable problem...

  1. #1

    Weird PHP Session variable problem...

    I have a script that first sets $_SESSION[order_status] = 'complete', then changes the header location to a new php page, with ?order_status=$_SESSION[order_status] attached to the URL. This new page checks to see if $_SESSION[order_status] == 'complete', and if not, gives a die() error. For some reason, this new page is not recognizing the $_SESSION variable, it's so weird... I can look in the URL and see ?order_status=complete, so I know the variable has been set correctly, but for some reason it just isn't being picked up on this new page. Here's the code in the new page:

    "first" page:
    PHP Code:
    if (mail($to$subject$message$headers)) {
            
    $_SESSION['order_status'] = 'complete';
            
    header ("Location:  http://www.am-eagle.com/checkout-confirm.php?order_status=$_SESSION[order_status]");
        } 
    beginning of "new" page:
    PHP Code:
    session_start();
    if ( 
    $_SESSION['order_status'] != 'complete' ) {
                 die(
    'Sorry, either you have reached this page in error, or we are experiencing technical difficulties. Please <a href="mailto:">email us</a> if the problem persists. Thank you!');
        } 
    Any ideas? This has been driving me nuts all morning.
    Last edited by shane-c; January 12th, 2007 at 04:25 PM.

  2. #2
    OK, upon further investigation, I am finding that only the $_SESSION[order_status] variable is being "unset", as I can get other session variables to display on this new page when I take out the die() if statement. There is nothing on this page that should "unset that", especially since there is basically no code above the line that checks to see if it exists. And on the previous page, this variable is assigned immediately before the header( Location: ) call.... I am going insane here....

    EDIT: I found someone on php.net that had a similar problem (losing sessions upon header redirect)... they also said that the problem does not occur with PHP5.... But that doesn't quite make sense, because my other SESSION variables are intact, just not the one created on the "first" page (shown above).
    Last edited by shane-c; January 12th, 2007 at 04:52 PM.

  3. #3
    OK, after digging around a bunch of forums for a while, I found someone who had the same problem, and somebody suggested putting
    PHP Code:
    session_write_close(); 
    above the header(). This worked for me... although I still don't understand the whole issue. Oh well.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012