I am trying to create an admin login page. LOGIN PAGE
After I login everything is normal. But when I try to enter another page or refresh the current login page the session resets itself.
Here is a user to test on your own:
username -> test
password -> test
EDIT!!! { Session is started in core.inc.php } !!!
Here is my code of core.inc.php:
 session_start;
 function admin() {
    if ( isset($_SESSION['id']) && !empty($_SESSION['id']) ){
        return true;
    }
}
Here is admin.php: (note: admin.php includes core.inc.php)
    
    if (isset($_POST["username"]) && isset ($_POST["password"])) 
{
    $username = $_POST["username"];
    $password = $_POST["password"];
    $query = "SELECT `id` FROM `admins` WHERE `username`='".mysql_real_escape_string($username)."' AND `password`='".mysql_real_escape_string($password)."'";
    if ($query_run = mysql_query($query))
    {
        $query_num_rows = mysql_num_rows($query_run);
        if ($query_num_rows == 0)
        {
            echo "<br><div style=\"background-color:lightyellow;text-align:center;border-color:darkblue;font-style:italic;width:80%;border-style:dotted;\">Incorrect username or password.</div>";
        }
        else if ($query_num_rows == 1)
        {
            $user_id = mysql_result($query_run, 0, 'id');
            $_SESSION['id'] = $user_id;
        }
    }
}
if ( admin() == true ) {
?>
<center><a href="logout.php"><input type="button" value="Log Out!" ></a></center>
            <? 
}   
else {
?>
            <form action="" method="post">
                <center>
                    <table style="width:300px;text-align:center;line-height:30px;">
                    <th>LOG IN!</th>
                    <tr>
                        <td> <input type="text" name="username" placeholder="Username:" required=""> </td>
                    </tr>
                    <tr>
                        <td> <input type="password" name="password" placeholder="Password:" required=""> </td>
                    </tr>
                    <tr>
                        <td> <input type="submit" value="Login!"> </td>
                    </tr>
                </table>
                </center>
            </form>
            <?
}
            ?>
 
     
    