My understanding of PHP sessions is that they let us track variables from page to page on a site. But I seem to be seeing something different with WordPress. I have the hook below in my functions.php file:
add_action( 'wp', 'sa_clear_session_email' );
function sa_clear_session_email() {
if ( ! is_page( 'Pricing ' ) )
return;
$ret = session_start();
if ($ret) {
$s_id = session_id();
trace("M20D:Pricing page. Started session $s_id");
}
else {
trace("M20E:Pricing page. Unable to start session");
}
unset( $_SESSION['user_email'] );
So, if this is the Pricing page, the code opens a session and clears the 'user_email' variable.
Also in functions.php is
add_action( 'wp', 'woa_add_membership_auto_on_checkout' );
function woa_add_membership_auto_on_checkout() {
if ( ! is_page( 'checkout' ) || ! is_checkout() ) {// is_checkout() returns true if viewing the checkout page
return;
}
$ret = session_start();
if ($ret) {
$s_id = session_id();
trace("M9F:Started session $s_id");
}
else {
trace("M9F:Unable to start session");
}
$email = $_SESSION['user_email'];
This code waits for the checkout page and then tries to use the session opened in the first code. The issue I'm having is that even though I cleared 'user_email' in the first hook function it's not cleared in the second, and the reason is that the session_id I get in the first code is not the session_id I get in the second code.
Does anyone understand what's happening here?
Thanks.

initaction is used to start the session. If that doesn't work, it's probably your server isn't saving sessions properly. - ub3rst4r