PHP - 会话不会导致带标头的重定向

问题描述:

I am trying to make the user get redirected to the index.html page in case the $_SESSION['loggedin'] is already set. For some reason, it doesn't redirect the user, although the $_SESSION['loggedin'] when echoed returns a value.

if(!empty($_SESSION['loggedin'])) { header('Location: index.html');};

What am I doing wrong here?

我试图让用户被重定向到index.html页面以防$ _SESSION ['loggedin' 已经设定好了。 出于某种原因,它不会重定向用户,虽然回显时$ _SESSION ['loggedin']会返回一个值。 p>

  if if(!empty($ _ SESSION ['  loggedin'])){header('Location:index.html');}; 
  code>  pre> 
 
 

我在这里做错了什么? p>

header('Location: index.html'); sets an http header which needs to be set before any content is sent, i.e. before any echo. Also you should terminate your script after you set the location header.