Session variable wont keep user logged in

Im trying to create a login system that creates a session if the user logs in to the member page. Once in the member page they can press logout to end the session otherwise if they dont, whenever they open up the login page they are redirected to the member page with their details displayed as if they have just logged in again.

How can i do this?

So far ive got this to create the session:

$result = $conn->query($SQL); 

    if ($result->num_rows>0)
    {
        //user information available in database
        echo "Login successful";
        echo "<br><br> re-directing to members page";
        $_SESSION['userlogin'] = $User_login;
        header ( 'refresh:5; url=member.php?id='.$Username ); //re-directing to member page
    }

And ive added the if isset:

<?php //Start of the PHP script
session_start();


if(!isset($_SESSION['userlogin']))
{

}

3 posts were merged into an existing topic: Using session variables to keep user logged in if they havent logged out