0

When the user get login route:


$app->get('/admin/login', function() {

    User::checkCookie();

    $page = new PageAdmin([
        "header"=>false,
        "footer"=>false
    ]);

    $page->setTpl("login");
});

I created the method "checkCookie" to know if the client has cookies :


public static function checkCookie() {

        if (!isset($_COOKIE["username"])) {
            header("Location : /admin/login");
        } else {
            header("Location : /admin");
        }
    }

However, when i access the route appears the " 500 Internal Server Error ", so I would to know what's happening and how to solve it.

With the method "login" is effetuated the user's login and if the " remember box" is checked the method will create the cookies.


public static function login($login, $password, $rememberCheck):User
    {

        $db = new Sql();

        $results = $db->select("SELECT * FROM tb_users WHERE deslogin = :LOGIN", array(
            ":LOGIN"=>$login
        ));

        if (count($results) === 0) {
            throw new \Exception("Não foi possível fazer login.");
        }

        $data = $results[0];


        if (password_verify($password, $data["despassword"])) {

            $user = new User();
            $user->setData($data);

            $_SESSION[User::SESSION] = $user->getValues();

            return $user;

        } else {

            throw new \Exception("Não foi possível fazer login.");

        }

         if($rememberCheck=='1' || $rememberCheck=='on')
        {
            setcookie("username", $login, time() + 3600, "/");
            setcookie("password", $password, time() + 3600, "/");
        }

print - error

rr1000
  • 11
  • 1

0 Answers0