samedi 25 février 2017

Login Page error

Hello Guys! I am facing problem in the login page. When I press login button it takes me to userpanel only if Remember me checkbox is checked. if it is not checked then It stays on login page. I cannot figure out error.

<?php
    include("Database/database.php");
    session_start();

    if(isset($_COOKIE['username']) and isset($_COOKIE['passcode']))
    {
        $username = $_COOKIE['username'];
        $passcode = $_COOKIE['passcode'];

        $_SESSION['name'] = $username;
        $_SESSION['pwd'] = $passcode;

        header("Location: useraccount.php");   /*Checks if cookies are set then takes me directly to useraccount.php */

    }

     else if(isset($_POST['login']))
    {
        $username = $_POST['username'];
        $userpwd = $_POST['userpwd'];
        $rem = $_POST['remember'];

        $query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'";

        $result = mysqli_query($link, $query);
        $row = mysqli_num_rows($result);

        if($row > 0)
        {
            $_SESSION['name'] = $username;
            $_SESSION['pwd'] = $userpwd;

            if (isset($_POST['remember']))     /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */
            {
                setcookie("username", $username, time()+60*60*7);
                setcookie("passcode", $userpwd, time()+60*60*7);
            }

            header("Location: useraccount.php");     /* It should procees to              useracocunt.php page but it stays on login.php*/
        }

        else
        {
            header("Location: login.php");      /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/
        }
        mysqli_close($link);

    }

    ?>




Aucun commentaire:

Enregistrer un commentaire