简体   繁体   中英

PHP $_SESSION not sharing through pages

I decided to update my Synology server. This update included the newest PHP version. Before I was able to use session_register() and session_is_registered() functions. These functions are deprecated and therefor I refactored the code using $_SESSION[]. The issue however is that I am not able to read the session on another page.

Page 1

<?
session_start();

$_SESSION['page1'] = "page1session";

//Check if page2 is set on other page
if (isset($_SESSION['page2'])) {
   echo "Received the session from page 2";
} else {
   echo "No session info from other page";
}

//Dump all session info:
var_dump($_SESSION);

Page 2

<?
session_start();

$_SESSION['page2'] = "page2session";

//Check if page2 is set on other page
if (isset($_SESSION['page1'])) {
   echo "Received the session from page 1";
} else {
   echo "No session info from other page";
}

//Dump all session info:
var_dump($_SESSION);

So therefore I figured, that the session is not able to be written (due to write privileges) to the session.save_path path in php.ini. This path was set to /var/services/tmp and is listed as session.save_path when I run php_info(); Therefore, I thought that the update set this new path as a new session path and that the folder does not have global read/write privileges. Therefore I logged in with SSH and ran the following code to set the rights recursively

chmod -R 777 /var/services/tmp

After setting the rights I restarted the apache services.

Unfortunately, I am still NOT able to save or open a session on another page.

var_dump on page 1 gives back page1 => page1session, and no session info on page 2. And page to outputs page2 => page2session.

What is going wrong folks.

Thanks in regards,

Alex

  1. Clear your session directory, open page 1, check that a session file has been written. If it hasn't, then double check your save path (maybe die(session_save_path()); in your script to be 100% sure you got the right path). You may also try setting your session save path to just /tmp for now, just to help eliminate the cause.

  2. If session files are being written, then check that the session cookie is being written. Once again, check the session cookie name in your script to be sure, and maybe get a cookie viewer plugin for your browser (firefox and chrome has plenty of these). Also worth dumping $_COOKIE variable so you know if the cookie is being passed through (just in case something weird is happening like being limited to a specific path within your domain)

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