从上面的问题,目前我已经创建了一个登录页面。在登录页面中,我将“电子邮件”作为会话包含在内,并且可以借用“所有页面中的电子邮件”。假设我想在会话中包含其他数据,例如“全名”,该怎么办?
下面是我的登录代码
<?php
include("config/configPDO.php");
session_start();
$msg = "";
if(isset($_POST['submitBtnLogin'])) {
$user_id = trim($_POST['email']);
$email=explode('@',$user_id);
if (is_array($email)){
$user_id=$email[0];
}
$pwd = trim($_POST['pwd']);
if($user_id != "" && $pwd != "") {
$ldap_dn = "TOPGLOVE\\".$user_id;
$ldap_password = $pwd;
$ldap_con = ldap_connect("ldap://172.xx.xx.xx:xxx");
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
if(@ldap_bind($ldap_con,$ldap_dn,$ldap_password)){;
try {
$records = $conn->prepare("SELECT email, roles_id, pwd FROM users WHERE user_id = :user_id ");
$records->execute(
array(
'user_id' => $user_id,
)
);
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if($results && count($results) > 0 ){
$_SESSION['login_user'] = $results["email"];
if($results["roles_id"] == "1"){
header("location: pages/dashboard/dashboard_admin.php");
}else if ($results["roles_id"] == "3"){
header("location: pages/dashboard/dashboard_super_admin.php");
}
} else {
echo "
<script>alert('You're not authorized to use this system')</script>
<script>window.location = 'index.php'</script>
";
}
} catch (PDOException $e) {
echo "Error : ".$e->getMessage();
}
} else{
echo "
<script>alert('Invalid Email or Password')</script>
<script>window.location = 'index.php'</script>
";
}
} else {
$msg = "Both fields are required!";
}
}
?>