简体   繁体   中英

Why is my PHP session array disappearing between page reloads?

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM