I have a main page that has a log in link on it that takes the user to a login page. However, if a user is already logged in I want to take the user to another page, for example a info page.
I have this function:
function logged_in_redirect() { if (logged_in() === true) { header('Location: client.php'); exit(); } } I'm wondering where to put this? I've tried pretty much everything. If i put this on the login page, it does not redirect me when i am logged on. I've tried adding it as an onclick function for the link on the home page but it didn't work.
This is my logged_in() function:
function logged_in() { return (isset($_SESSION['user_id'])) ? true : false; } Any suggestions?
Edit:
I have currently fixed the problem by making the button on the home page link to a test.php file which has this code:
<?php include 'core/init.php'; if (isset($_SESSION["user_id"])) { header('Location: client.php'); } else { header('Location: info.php'); } ?> Is there any way around this?
echo var_dump(logged_in());header('Location: client.php');<-- theLocationheader is only valid for absolute URLs. While browsers are usually lenient in not requiring a full URL, you should never rely on relative URLs. Change toheader('Location: http://'.$_SERVER['HTTP_HOST'].'/client.php');