recursive session_start
Posted: Fri Feb 13, 2009 1:55 pm
I'm new to php, and I'm trying to use session variables to perpetuate values from page to page. I have a .php form page that gets called multiple times (sometimes by itself and sometimes by PayPal) and it responds differently based on input parameters etc.
My problem is that the first time it's called it's a data entry form (at which time it starts the session and creates session variables), then it posts to itself to validate the variables, then it posts to PayPal. PayPal then sends its payment notification back to the same form. But the session variables are no longer available at that time. I'm assuming the session_start call is starting a new session (for testing purposes I found that a separate form could start a session and see the values that the multi-purpose form had set). I've tried several conditional session_starts, like the one below, to try to not start a new session if it's seen that a session is already active, but I haven't got it worked out yet. I see that the session ID is different between the time the page sets the variables and when it tries to read them (but the same when comparing the original setting and a later reading by a separate page).
I suppose I could simply split the code into separate pages so I wouldn't have to be concerned over starting a new, separate session, but it's hard for me to accept that there's not a simple way to rejoin the existing session.
Any suggestions?
<?php
if (isset($_SESSION['ID'])) { session_start($_SESSION['ID']); } else { session_start(); }
$_SESSION['ID'] = session_id();
My problem is that the first time it's called it's a data entry form (at which time it starts the session and creates session variables), then it posts to itself to validate the variables, then it posts to PayPal. PayPal then sends its payment notification back to the same form. But the session variables are no longer available at that time. I'm assuming the session_start call is starting a new session (for testing purposes I found that a separate form could start a session and see the values that the multi-purpose form had set). I've tried several conditional session_starts, like the one below, to try to not start a new session if it's seen that a session is already active, but I haven't got it worked out yet. I see that the session ID is different between the time the page sets the variables and when it tries to read them (but the same when comparing the original setting and a later reading by a separate page).
I suppose I could simply split the code into separate pages so I wouldn't have to be concerned over starting a new, separate session, but it's hard for me to accept that there's not a simple way to rejoin the existing session.
Any suggestions?
<?php
if (isset($_SESSION['ID'])) { session_start($_SESSION['ID']); } else { session_start(); }
$_SESSION['ID'] = session_id();