Create one function to check if user logged in php
<p>I want to create a function that will check if the user is logged in. If so, the user should be navigated to userActive, otherwise the loginForm should be displayed.</p>

<p>I also want to carry out a check on the loginForm page to check if the user is logged in. If so, they should be taken to userActive, or kept on the loginForm page.</p>

<p>Why issue is why the following code doesn't work. I keep hitting a loop.</p>

<pre><code>$_COOKIE['user_id'] = "user_id: 1";

activeUser();

function activeUser()
{
    if($_COOKIE['user_id'] == "user_id: 1")
    {
        header('location: index.php?a=activeUser');
    }
    else
    {
        header('location: index.php?a=loginForm');
    }
}

switch($_GET['a'])
{
    case 'loginForm':
        include_once('loginForm.php');
    break;

    case 'activeUser':
        include_once('activeUser.php');
    break;
}
</code></pre>
