Q:

How to create a PHP login counter

Im going to start by saying im obviously a high school student so this is not for an actual site, so im just trying to learn something new but its not as easy as I thought. Im trying to make a login counter that echos a numbers remaining everytime a fail attempt to login is executed. Once the counter reaches 0 it should redirect to google. My problem is that the Session variable wont count down. If someone could help I would be grateful.
session_start();

if($_POST['submit']=='submit')
{   

$_SESSION[x]=5;

if($_POST['ps']=='happy8')
{
    $_SESSION[ps]=1;
    header('Location: private.php');
    exit();  
}
elseif($_POST['ps']!='happy8')  
{

    if($_SESSION[x]>1)
    {
        $output='<p style="color:red">You have '.$_SESSION[x].' attempts left</p>' ;
        $_SESSION[x]=$_SESSION[x]-1;

    }

        if($_SESSION[x]==0)
        {

            session_destroy();  
            header('Location: https://www.google.com/'); 
                exit();
        }

}

} 

A:

Everytime you submit the form you set the tries to 5: $_SESSION[x]=5
You should make something like this:
session_start();

if (!isset($_SESSION[x]) $_SESSION[x]=5;
//Otherwise nothing, preserve the session value

if($_POST['submit']=='submit') {   
    ...
}

Also, I don't know waht $_SESSION[x]==5; makes in this place:
    if($_SESSION[x]==0)
    {
        $_SESSION[x]==5;
        session_destroy();  
        header('Location: https://www.google.com/'); 
            exit();
    }

There you are comparing value not assigning.

