dongwen2162 2013-08-10 18:07
浏览 17

保持LDAP用户使用PHP会话登录

UPDATED According to advice below. But still not working. Any help?

My company uses Active Directory LDAP and I'm using adLDAP to authenticate the user to login to this website.

So far, it works.. but every time they visit the page they must login again. The solution to this, I know is sessions. But I can't figure out what to store in the session in order to keep the user logged in.

This is included at the top of my login.php page:

auth.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
  }
?>

Also at top of every page I have this:

<?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...
}
?>

Right now, everytime I visit my index page index.php I log in, and I'm redirected to the main page. It works perfectly. But if I refresh the page, I'm asked to login again.

What do I store into a session so I don't have to log in everytime I refresh the page?

I know it starts with:

session_start();

But I don't know what to store in it?

  • 写回答

1条回答 默认 最新

  • dongpu2727 2013-08-10 18:17
    关注

    You should only authenticate/include LDAP on your login page.. if success set a $_SESSION['LDAP']['login'] = true;

    And check on every page with this.

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大