简体   繁体   English

PHP会话无法正常工作

[英]PHP Sessions doesn't work correctly

Hi I am learning PHP and trying to build forum as a start. 嗨,我正在学习PHP,并尝试以建立论坛为起点。 Forum You can do the test and see how login session doesn't respond properly. 论坛您可以进行测试,并查看登录会话如何无法正确响应。 username: test password:test 用户名:测试密码:test

 <?php
//signout.php
include 'connect.php';
include 'header.php';

echo '<h2>Sign out</h2>';

//check if user if signed in
if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true)
{
    //unset all variables
    $_SESSION['signed_in'] = NULL;
    $_SESSION['user_name'] = NULL;
    $_SESSION['user_id']   = NULL;
    $_SESSION['user_level']   = NULL;


    echo 'Succesfully signed out, thank you for visiting.';
    echo " test";
}
else
{
    echo 'You are not signed in. Would you <a href="sign_in.php">like to</a>?';
}

include 'footer.php';
?>

You can log in but then through some pages it looks like you are not signed in or when trying to sign out it doesn't sign out properly. 您可以登录,但是然后通过某些页面,好像您尚未登录,或者尝试退出时登录不正确。

The problem is with sessions on my web hosting server. 问题出在我的虚拟主机服务器上的会话。 Locally on my computer it works fine under WAMP. 在我的计算机上,它在WAMP下可以正常工作。 Tested another web hosting it works fine. 测试了另一个虚拟主机,它工作正常。

Not sure what is it... 不知道这是什么...

How are you handling your sessions on each page? 您如何处理每个页面上的会话? It seems like it is generally set up properly, I have replied to "Topic Test" and it reports I have successfully replied, but it does not show up in the list. 看来它通常设置正确,我已答复“主题测试”,并且报告我已成功答复,但未在列表中显示。

The one thing that has messed me up in the past is forgetting to put session_start(); 过去让我感到困惑的一件事就是忘记放置session_start();。 at the top of the page, or in a function that feeds that page. 在页面顶部或提供给该页面的函数中。 Your session data will still be there but will not be accessible to the page and will not record any session data you try to store. 您的会话数据将仍然存在,但该页面无法访问,并且不会记录您尝试存储的任何会话数据。

Just quick update 只需快速更新

Problem was not with my script but with web hosting and "Unixy Varnish enabled". 问题不是我的脚本,而是Web托管和“启用了Unixy Varnish”。 I had to disable it. 我不得不禁用它。

Thank you for all the help 谢谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM