简体   繁体   English

如果用户未登录,则重定向PHP

[英]If user isn't logged in, then redirect PHP

I'm working on a site that I didn't build. 我正在一个未建的网站上工作。 I'm trying to put an HTML redirect inside an if statement, Here's the source: 我试图将HTML重定向放入if语句内,这是源:

<?php 
    if(!$usersClass->checkLoggedIn()) { 
?>
// Stuff here
<?php } else { ?>
    // More stuff here
<?php } ?>

I want to put a redirect within here: if the user isn't logged in, they're redirected to the homepage, I've tried the following with no luck. 我想在此处进行重定向:如果用户未登录,他们将被重定向到主页,我尝试了以下方法,但没有成功。 Can anybody see where I'm going wrong? 有人可以看到我要去哪里了吗?

<?php 

if(!$usersClass->checkLoggedIn()) { 
header("Location: /index.php");

?>

You forgot to close the bracket } 您忘记合上括号}

should be: 应该:

<?php 

if(!$usersClass->checkLoggedIn()) { 
  header("Location: /index.php");
}
?>

Try to give the full URL, and close the } bracket : 尝试提供完整的URL,然后关闭}括号:

<?php 

if(!$usersClass->checkLoggedIn()) { 
header("location: http://localhost/yoursite/index.php");
}
?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM