重定向后 $_SESSION 为空 [英] $_SESSION is empty after redirecting

查看:86
本文介绍了重定向后 $_SESSION 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有一点问题.我试图在用户登录后在我的会话中存储一些变量,然后我想将用户重定向到另一个站点.我已经用一些测试值替换了正确的变量,但无法弄清楚为什么这不起作用.

i have a little problem in my code. I am trying to store some variables in my session after a user has logged in and then i want to redirect the user to another site. I have replaced the correct variables with some testvalues, but can not figure out why this does not work.

登录站点代码为:

require_once ('SecureSessionHandler.class.php');

$session = new SecureSessionHandler('abcd');
$session->start();
$session->put("test", "test");
print_r($_SESSION);

if(isset($_POST['login']))
{
    //check User

    //login
    $session->put("userlogin", 1);
    header("location: index.php");
    exit();
}

echo "<form action ='' method='POST'>";

echo "<label for='username'>Name: </label>";
echo "<input type='text' name='username'><br>";

echo "<label for='passwort'>Passwort: </label>";
echo "<input type='password' name='passwort'><br>";

echo "<input type='submit' name='login' value='Anmelden'>";

echo "</form>";

print_r($_SESSION) 在这里工作得很好,它显示Array ( [test] => test )".

The print_r($_SESSION) works just fine here, it displays "Array ( [test] => test )".

第二个站点的代码是:

<?php
require_once 'SecureSessionHandler.class.php';
$session = new SecureSessionHandler('abcd');
$session->start();

//some stuff that is not relevant here

//check login
$userlogin = $session->get('userlogin');
print_r($_SESSION);
echo "<br>";

if($userlogin == 1)
{
    //do stuff
}

此处print_r($_SESSION) 显示Array ( )".

我不知道为什么会这样.我真的很感激你们能给我的任何帮助.

I have no idea why this is the case. I would really appreciate any help you guys can give me.

推荐答案

好的,

所以我不知道为什么现在按预期运行.我的管理员让我进行了一些安全更新和硬件重启,之后它只适用于标准的 php 会话函数和我的 SecureSessionHandler 函数.

so I do not know why this is now running as intended. My admin had me do some security updates and a hardware reboot and afterwards it just works with standard php session functions and with my SecureSessionHandler functions.

我想某些东西已经崩溃或阻止了对所需文件的访问.

I suppose something had crashed or blocked access to a file that was needed.

不过还是谢谢你的帮助.

But none the less, thank you for your help.

这篇关于重定向后 $_SESSION 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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