首先我设置会话,但当我print_r()
$_SESSION
时,它只显示Array() 1
我确实在session_start()
;
功能I使用:
function login($Username, $password, $pdo)
{
$sth = $pdo->prepare("SELECT * FROM `klanten` WHERE Inlognaam='$Username'");
$sth->execute();
if ($sth->rowCount() == 1) // als er een row is met die username dan gaat hij verder
{
// Variabelen inlezen uit query
$row = $sth->fetch();
$password = hash('sha512', $password . $row['Salt']); // encrypt het wachtwoord
if ($row['Paswoord'] == $password) // als het wachtwoord gelijk is aan het ingevulde wachtwoord
{
$user_browser = $_SERVER['HTTP_USER_AGENT']; // kijken welke browser je gebruikt
$_SESSION['user_id'] = $row['KlantID'];
$_SESSION['username'] = $row['Inlognaam'];
$_SESSION['level'] = $row['Level'];
$_SESSION['login_string'] = hash('sha512',$password . $user_browser);
// Login successful.
return true;
}
else
{
// password incorrect
return false;
}
}
else
{
// username bestaat niet
return false;
}
}
第2页
echo '<pre>' . print_r($_SESSION) . '</pre>';
仅返回Array()
答案 0 :(得分:1)
方法print_r
中的第二个参数是返回不打印,以获得这样的打印用途,
echo '<pre>' . print_r($_SESSION) . '</pre>';
从此处获取更多详细信息:http://php.net/manual/en/function.print-r.php
答案 1 :(得分:1)
**You might have not started the session.This worked for me**
<?php
session_start();
$_SESSION['user_id'] = $row['KlantID'];
$_SESSION['username'] = $row['Inlognaam'];
$_SESSION['level'] = $row['Level'];
$_SESSION['login_string'] = hash('sha512',$password . $user_browser);
echo '<pre>' . print_r($_SESSION,true) . '</pre>';
?>