Reputation: 9855
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:
<?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");
?>
Upvotes: 0
Views: 269
Reputation: 1096
Try to give the full URL, and close the }
bracket :
<?php
if(!$usersClass->checkLoggedIn()) {
header("location: http://localhost/yoursite/index.php");
}
?>
Upvotes: 0
Reputation: 53535
You forgot to close the bracket }
should be:
<?php
if(!$usersClass->checkLoggedIn()) {
header("Location: /index.php");
}
?>
Upvotes: 1