Session_ID keeps changing on refresh; Cookie isn't being sent to browser

跟風遠走 提交于 2019-12-12 02:23:28

问题


I've went through various threads about this problem and couldn't find a solution.

I'm using the following code:

<?php
session_start();
ini_set('display_errors', 'on');
error_reporting(-1);
session_name("hello");
$_SESSION['username'] = "name";
echo $_SESSION['username'];
echo session_id();
if (is_writable(session_save_path()))
{
    echo "writable";
}
?>  

This is the output:

name771e6d83a8578e2dbadac64dc62b5788writable

Yet the session ID output keeps changing on every page refresh.

It is happening in all browsers I tried (Chrome, IE, FF).

In none of the browsers I couldn't locate a PHPSESSID cookie that is supposed to be sent from my domain.

Since the output yields writable, this shouldn't be a permission problem.

These are my php.ini settings:

session_auto_start is set to 0, like I guess it should be.

What can be causing this problem?

I'm trying to learn sessions, started with this simple code and can't get over this issue.

Another note: As you can see, I've set error reporting, and I don't get any special errors when I test this code on my VPS server. However, when I run the same code on some shared hosting account that I have on another server, I'm getting a headers already sent on line 2 error. I don't what exactly is making the difference, but I intend to run my project only on my VPS server anyway.

来源:https://stackoverflow.com/questions/33825348/session-id-keeps-changing-on-refresh-cookie-isnt-being-sent-to-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!