当我重定向到用户时,我无法将数据存储到会话存储中,我该如何解决这个问题?如果添加一个视图而不是重定向,它可以工作..但是下面的代码不起作用..
public function makeLogin(){
$model = new User();
$user = $model->read()->where("username","=",post("username"))->first();
if(password_verify(post("password"),$user['password'])){
$_SESSION['auth']['user'] = $user['name'];
$_SESSION['auth']['username'] = $user['username'];
$_SESSION['auth']['user_role'] = $user['user_role'];
return redirect('redirect-core');
} else {
session("message","wrong username or password");
session("message_type","danger");
return redirect(ref_url());
}
}
session()
帮助
function session($name = null,$message=null){
if (is_null($name) && is_null($message)){
return new \Core\Session();
} else {
$_SESSION[$name] = $message;
}
}
redirect()
帮助
function redirect($url){
if (substr($url,0,4)==="http"){
header("Location:".$url,true,303);
} else {
header("Location:".APP_URL."/".$url);
}
}