PHP session_id 在刷新时永远不会相同 [英] PHP session_id never the same on refresh
问题描述
我试图在某些 php 页面上使用 session_id(),但是每个文件之间的 id 都会发生变化,并且每次刷新页面时都会发生变化.我放置了以下脚本,它应该在重新加载时增加,但它没有.
I am trying to use session_id() on some php pages, but the id changes between every file and it changes everytime i refresh the page. I placed the following script which should increment on ever reload, but it does not.
session_start();
if (!isset($_SESSION['hits'])) $_SESSION['hits'] = 0;
++$_SESSION['hits'];
echo '<p>Session hits: ', $_SESSION['hits'], '</p>';
echo '<p>Refresh the page or click <a href="', $_SERVER['PHP_SELF'],
'">here</a>.';
在我的 php.ini 文件中,我打开了 cookie 并设置了我的 save_path tp '/tmp'.
In my php.ini file, I have cookies turned on as well as set my save_path tp '/tmp'.
在实际文件夹中,有会话文件...所以我知道这不是文件写入问题.我还确保每个文件都是 utf-8 和 bom 以确保一致性.
In the actual folder, there are session files... so i know it is not a file writing issue. I have also ensured that every file is utf-8 with bom to ensure consistency.
如果您还有其他的解决方案,请帮我解决.它让我发疯.
If there are any other solutions you can think of, please help me solve this. It is driving me insane.
谢谢!!!
推荐答案
对于您的情况,我能想到的 3 种可能性是:
The 3 possibilities I can think of for your situation are:
- 你如何调用
session_id()
?在您的问题中包含该代码.如果您使用 any 参数调用它,它会将会话 ID 覆盖为您传递的任何参数. - 您的浏览器是否启用了 Cookie?会话 ID 作为 cookie 发送到浏览器.
- 您是否随时调用
session_destroy()
?这将从服务器中删除会话数据,并导致在后续网页浏览时启动新会话.
- How are you calling
session_id()
? Include that code in your question. If you're calling it with any arguments it will override the session ID to whatever argument you passed. - Are cookies enabled in your browser? The session ID is sent to the browser as a cookie.
- Are you calling
session_destroy()
at any point? This will delete the session data from the server and cause a new session to be started on subsequent pageviews.
这篇关于PHP session_id 在刷新时永远不会相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!