I have a sign-in page. Once a user is logged in, I want to use php to redirect to a new page. I am trying to do this by checking if a user id is set or not.
One: CONFIG FILE
session_start();
Two: MAIN PAGE
require ('config.php');
if (isset($_SESSION['user_id']))
{
echo'
<META http-equiv="refresh" content="0;URL=**signed in page URL here**>
';}
Up to here works fine. If a correct login is used, the redirection takes place.
Three: PAGE IF SIGNED IN
<?php
require ('config.php');
if (isset($_SESSION['user_id']))
{
echo'HTML CONTENT HERE';}
else{echo'Not Logged In';}
?>
At the new page, the above code is used but always returns 'Not logged in'. Why is this happening when to get to this step, the same if statement must be true? Why am i losing the session data?
Is there a better way to redirect a logged in user without using headers?
Kind regards,