Reputation: 79
I tried redirecting my play.php(main page) to my index page, where the user needs to log in. It works. However, users can't log into the play.php, because it keeps redirecting. I used the codes below to achieve that. I placed it immediately after the body tag()
<?php
header("Location: index.php");
exit();
?>
Upvotes: 2
Views: 3281
Reputation: 1100
There is no condition for getting user logged in or not. You should create a function that checks user status and returns true or false. Create a check function with name isUserLoggedIn and use it this way:
<?php
if(!isUserLoggedIn()){
header("Location: http://example.com/index.php");
exit();
}
?>
Upvotes: 3