Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $\仅在页面重新加载后读取会话_Php_Mysql_Session - Fatal编程技术网

Php $\仅在页面重新加载后读取会话

Php $\仅在页面重新加载后读取会话,php,mysql,session,Php,Mysql,Session,最近我正在尝试解决一些有关会话的问题,现在我需要帮助获得一个使用XAMPP的小页面。 我使用4页进行测试: 1) index.php是用户放置ID和PW的页面。 2) logon.php检查数据库中是否有匹配的条目,并将einter重定向到index.php或profile.php 3) profil.php回显所有相关的用户数据 4) logout.php 测试1:现在作为一个用户,我做了以下工作:从index.php开始,输入我的ID和PW。我的身份证是1234。登录表示我很好,并将我重

最近我正在尝试解决一些有关会话的问题,现在我需要帮助获得一个使用XAMPP的小页面。

我使用4页进行测试:
1)
index.php
是用户放置ID和PW的页面。
2)
logon.php
检查数据库中是否有匹配的条目,并将einter重定向到
index.php
profile.php

3)
profil.php
回显所有相关的用户数据
4)
logout.php


测试1:现在作为一个用户,我做了以下工作:从index.php开始,输入我的ID和PW。我的身份证是1234。登录表示我很好,并将我重定向到profil.php,显示用户1234的数据。现在我可以注销了,会话被删除了,一切看起来都很好。

测试2:作为一个新用户,我从
index.php
开始,但现在我的ID是5678
logon.php
告诉我一切正常,并将我重定向到
profil.php
,但它显示了第一次登录时的数据(1234)。我也可以移动到其他页面并返回到
profil.php
,但在刷新页面(F5或CTRL+SHIFT+R)之前,数据将始终用于用户1234。不管是哪种方式,现在都会显示正确的5678数据。我可以注销,会话将再次被销毁

以下是我如何处理会话:

index.php

<?php
    @session_start();
?>
<?php
    @session_start();
    if(!isset($_SESSION['personal_id'])){
        header('Location: /index.php');
        exit;
    }
?>
<?php
    @session_start();
    $_SESSION = array();
    setcookie( session_name(), "", time()-3600, session_save_path() );
    session_destroy();
    session_write_close();
?>
profile.php

<?php
    @session_start();
?>
<?php
    @session_start();
    if(!isset($_SESSION['personal_id'])){
        header('Location: /index.php');
        exit;
    }
?>
<?php
    @session_start();
    $_SESSION = array();
    setcookie( session_name(), "", time()-3600, session_save_path() );
    session_destroy();
    session_write_close();
?>
所有标题如下所示:

<head>
    <title>Scheffel Shoptime</title>
    <link href="style.css" rel="stylesheet" type="text/css">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Refresh" content="5;url=./index.php">
</head>

谢菲尔购物时间
你能看到我哪里出了问题吗,或者你需要进一步的信息吗?
提前感谢所有试图帮助你的人

我实际上在缓存问题中找到了解决方案。我在标题中使用了以下代码:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

并将其更改为:

<?php
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
?>


我不知道HTML版本的哪一部分是错误的,但PHP版本运行良好,从而解决了我的问题。非常感谢您的想法和意见

为什么要使用
session\u regenerate\u id(true)?没有太多意义,如果不执行,这可能就是问题所在。你为什么要这样做我仍在学习如何使用会话。我浏览了stackoverflow上的其他页面,说明我应该使用session_start();在每一页上,我都评论了session\u regenerate\u id(true);我想,但这似乎不是问题所在。我使用它来确保每次登录时都使用新会话。您实际在哪里设置
$\u session['personal\u id']