session_start()每次刷新都会创建新的会话 [英] session_start() creates new session every refresh

查看:415
本文介绍了session_start()每次刷新都会创建新的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在session_start()上遇到问题.每次刷新/加载页面时,它都会创建一个新会话.

I am having an issue with session_start(). It is creating a new session every refresh/load of the page.

下面是代码:

<?php
    $bob = session_id();
    echo "Session ID on load is ".$bob;
    echo "<br>";
    if($bob==""){
        session_start();
        $bob = session_id();
        echo ' session ID currently is '.$bob;
    }
// a bunch more stuff

加载页面时,我得到以下信息:

when i load the page, I get the following:

正在加载的会话ID为 会话ID当前为ed320bc5e24c871c9db8ea30e6796c14(或变体)

Session ID on load is session ID is currently ed320bc5e24c871c9db8ea30e6796c14 (or a variant)

如果刷新页面,我会得到:

if I refresh the page i get:

正在加载的会话ID为 会话ID当前为fbd69d01d511a7be382799dca7279a86(或变体)

Session ID on load is session ID is currently fbd69d01d511a7be382799dca7279a86 (or a variant)

在调用session_start()之前,会话ID始终为空,并且始终为新的session_id()

the session Id is always blank before session_start() is called and it is always a new session_id()

它在所有浏览器中都执行此操作,并且我已检查以确保已打开Cookie.

It does this in all browsers and I have checked to make sure cookies are turned on.

会话保存路径指定为/tmp.我不确定确切的位置,但是通过我的根目录和所有其他目录,我找不到会话文件(假设它看起来像sess_fbd69d01d511a7be382799dca7279a86).

the session save path is given as /tmp. I am not sure exactly where that is, but looking through my root and all other directories, I can't find a session file (assuming it would look something like sess_fbd69d01d511a7be382799dca7279a86).

因此,我认为保存路径有些问题,但是对此尚不成熟,无法确定,服务器管理员对此毫无帮助.我在诊断问题时应该采取的下一步措施是什么?服务器正在运行5.3.22.

So I am thinking there is something going on with the save path, but am too new at this to know for sure, and the server admins are being fairly unhelpful. What should my next steps at diagnosing the issue be? The server is running 5.3.22.

phpinfo是此处

感谢您的帮助.

ps,如果您愿意,可以访问pcm.pcmxa.com亲自查看问题.

ps you can visit pcm.pcmxa.com to see the issue for yourself if you wish.

推荐答案

如果您的会话目录(最像您所说的/tmp )是不可写的,则它将无法保存并且每次都必须重新生成一个新的.您可以通过以下方法进行验证:

If your session directory (most like /tmp as you said) is not writable, then it won't be able to save and will have to regenerate a new one each time. Here is how you can verify it:

if (!is_writable(session_save_path()))
{
 echo 'Session save path "'.session_save_path().'" is not writable!'; 
}

在这种情况下,您需要让服务器管理员向您的网络服务器运行的所有用户授予写入/tmp目录的权限.

If that is the case, you will need to have the server admins give what ever user your webserver runs as permission to write to the /tmp directory.

这篇关于session_start()每次刷新都会创建新的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆