简体   繁体   中英

PHP session doesn't persist on new server

First off, I did read at least 10 similarly named questions and answers and did not resolve the issue.

I had a working AJAX-based login script, but now that I've copy-pasted the entire site to new hosting, it doesn't work.

The process is simple.

Javascript sends login data to ajax.php , where this happens:

session_start();

//check database

$_SESSION['isloggedin']=1;
//if I var_dump($_SESSION) here, it prints out `array{'isloggedin' => 1}`

echo "ok";

Then Javascript redirects to index.php , which is currently:

session_start();
var_dump($_SESSION);

But here, $_SESSION is an empty array!

If I do echo session_id(); on both pages, it prints out the same value.

What could possibly be the issue here?

Remember, it worked perfectly on a different server.

Have you tried basic session increment test by reloading one page in the browser? For example:

<?php
session_start();
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>

Is it working?

If you store session data in files (default PHP configuration): Can you access folder, where session files are stored? Is anything stored in session file, that assigned to your session?

first thing is in which page you use session you have to write first line is session_start() ok?

please try this i hope your problem solve

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