Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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