SESSION 变量在需要 SIMPLESAMLPHP 后不起作用

SESSION variables not working after require SIMPLESAMLPHP

我的会话变量有问题。

我不能在我要求一次后设置任何变量。 但是我需要在登录后存储我的数据。

这是代码:

<?php include "include/header.php";

require_once('simplesamlphp/lib/_autoload.php');
$as = new \SimpleSAML\Auth\Simple('default-sp');

$as->requireAuth();

$attributes = $as->getAttributes();

$_SESSION["nivauth"] = "test";

?>

编辑:

我在另一页上有这个错误: Notice: Undefined index: nivauth in /var/www/html/cableEdit.php on line 10

我的会话 var nivauth 仅在我的第一页可用。

我的session_start()可以正常使用,我的其他session变量都是在其他页面创建的,可以查看。

如果我将 $_SESSION["nivauth"] = "test"; 放在 include 下,一切正常,但我无法从身份验证中获得 nivauth。

var 已创建但无法在其他页面上访问...

参考this part of the documentation

If we are using PHP sessions in SimpleSAMLphp and in the application we are protecting, SimpleSAMLphp will close any existing session when invoked for the first time, and its own session will prevail afterwards. If you want to restore your own session after calling SimpleSAMLphp, you can do so by cleaning up the session like this:

$session = SimpleSAML_Session::getSessionFromRequest();
$session->cleanup();

If you don't cleanup SimpleSAMLphp's session and try to use $_SESSION afterwards, you won't be using your own session and all your data is likely to get lost or inaccessible.

cleanup() 根本不起作用所以除了 $session->cleanup() 之外,我还做了两处更改以使其工作

1- config/config 中的空 session.phpsession.cookiename。php

'session.phpsession.cookiename' => ''

2- 添加了 session_start();清理后()

$session = SimpleSAML_Session::getSessionFromRequest();
$session->cleanup();
//session_write_close();
session_start();

我在使用 SimpleSamlPHP 时遇到了类似的问题。在尝试了各种解决方案后,终于通过以下解决方法解决了我的问题。

在您的 header.php(或其他页面)中,而不是 session_start(); 通过添加以下两行来启动 SimpleSamlPHP class 您可以恢复您的自定义会话变量以及 simplesamlphp 会话。

require_once('simplesamlphp/lib/_autoload.php');
$as = new \SimpleSAML\Auth\Simple('default-sp');

这是片段。

<?php
//header.php
//session_start();
require_once('simplesamlphp/lib/_autoload.php');
$as = new \SimpleSAML\Auth\Simple('default-sp');

echo $_SESSION["nivauth"];