0

更新根据以下建议。但仍然无法正常工作。有什么帮助吗?

我的公司使用 Active Directory LDAP,我正在使用 adLDAP 对用户进行身份验证以登录该网站。

到目前为止,它有效..但每次他们访问该页面时,他们都必须再次登录。我知道的解决方案是会话。但我无法弄清楚在会话中存储什么以保持用户登录。

这包含在我的login.php页面顶部:

授权文件

<?php
//include LDAP authenication script
 require_once('LDAP/adLDAP.php');
  $adldap = new adLDAP();
  $username = $_POST['account'];
  $password = $_POST['password'];
  $authUser = $adldap->authenticate($username, $password);
  $userinfo = $adldap->user_info($username, array("*"));
  if ($authUser == true) {
  $_SESSION['LDAP']['login'] = true
  }
?>

在每一页的顶部我都有这个:

<?php
if (empty('LDAP')) session_start();
if (!isset($_SESSION['LDAP']['login'] && $_SESSION['LDAP']['login'] !== true) {
header('Location: login.php');
exit; // dont forget the exit here...
}
?>

现在,每次我访问我的索引页面index.php时,我都会登录,然后我会被重定向到主页。它完美地工作。但是如果我刷新页面,我会被要求再次登录。

我将什么存储到会话中,这样我就不必每次刷新页面时都登录?

我知道它始于:

session_start();

但是不知道里面放什么?

4

1 回答 1

2

您应该只在登录页面上验证/包含 LDAP。如果成功设置 $_SESSION['LDAP']['login'] = true;

并检查每一页。

if (!isset($_SESSION['LDAP']['login'] && $_SESSION['LDAP']['login'] !== true) {
   header('Location: login.php');
   exit; // dont forget the exit here...
}
于 2013-08-10T18:17:28.223 回答