Reputation: 468
I can't figure out why my PHP session array disappears between page loads. The following code makes session_start() available on each page load:
<?php
session_start();
if ( isset( $_SERVER['QUERY_STRING'] ) && !empty($_SERVER['QUERY_STRING']) ) {
$gmeta_query_string = $_SERVER['QUERY_STRING'];
parse_str( $gmeta_query_string, $gmeta_query_array );
var_dump($gmeta_query_array);
foreach ( $gmeta_query_array as $key => $value ) {
$_SESSION[ 'gmeta_query_array' ][$key] = $value;
}
}
var_dump( $_SESSION );
echo session_id();
?>
Thinking perhaps it could be my server, here are some test URLs. This first link creates a session array and print its out, the second does prints an empty session array. Code is the same on both pages.
http://barbadospropertylist.com/wp-content/plugins/gravitymeta/test.php?name=value
http://barbadospropertylist.com/wp-content/plugins/gravitymeta/test.php
And here's a link to the PHP info: http://www.barbadospropertylist.com/phpinfo.php
Upvotes: 1
Views: 1555
Reputation: 5685
The same type of question was asked by another user in SO, and got it resolved.
Please check if it can help you PHP session is not working
Can you print the session_id, whether it's not changed on each page load?
Upvotes: 1