【发布时间】:2016-11-23 09:48:52
【问题描述】:
您好,当我尝试将重定向发送到登录页面时出现此错误。 这是我的代码...
本地主机页面不工作
localhost 将您重定向了太多次。尝试清除您的 cookie。 ERR_TOO_MANY_REDIRECTS
我正在尝试的任何东西都会给我这个错误。
任何建议将不胜感激,谢谢!
<?php
if(!$session->is_signed_in()){
header("Location:login.php");
} else{
header("Location:logout.php");
} ?>
还有这个
class Session{
private $signed_in = false;
public $user_id;
public function __construct(){
session_start();
$this->check_the_login();
}
// check the value of signed in property - getter method
public function is_signed_in(){
return $this->signed_in;
}
// login method
public function login($user){
if($user){
$this->user_id = $_SESSION['user_id'] = $user->id;
$this->signed_in = true;
}
}
// log out method
public function logout(){
unset($this->$_SESSION['user_id']);
unset($this->user_id);
$this->signed_in = false;
}
// check the login method
private function check_the_login(){
if(isset($_SESSION['user_id'])){
$this->user_id = $_SESSION['user_id'];
$this->signed_in = true;
}else{
unset($this->user_id);
$this->signed_in = false;
}
}
}
$session = new Session();
【问题讨论】:
-
把
exit()放在header()之后 -
第一段代码来自哪个页面?
login.php? -
我将 exit() 放在标题之后,我得到了相同的结果。 @Jon - 第一段代码是 index.php 标头的一部分
-
开始会话 session_start();
-
@Cristi 在您的开发工具中,在网络下,您应该看到正在发生的重定向。正在重定向到哪些文件?
标签: php