我尝试了很多次......但它没有重定向到任何地方:
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: LogIn.php");
exit;
}
else{
//Content of the webpage
}
?>
我该如何解决这个问题?
答案 0 :(得分:0)
我测试了它,它适用于我。确保在header
功能之前没有任何输出。它也可能由error_reporting
引起。尝试使用error_reporting(0);
。
答案 1 :(得分:0)
尝试使用像这样的绝对URl:
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: http://www.mysite.com/LogIn.php");
exit;
}
else{
//Content of the webpage
}
?>
要尝试的另一件事是确保没有首先发送标头;如果页面上有任何可见的错误,将会出现。
答案 2 :(得分:0)
首先检查session
变量是否具有该值并输入if
条件。如果可行,请尝试使用标题中的完整网址。