Failed to create login system

Asked

Viewed 167 times

-4

I’m making a PHP login system that checks two conditions.

1st If wrong login or password has been entered;
2nd If the direct URL has been typed.

The first check is correct. I’m having trouble in the second condition. When I enter the correct login and password, the system redirects to the denied access page.

<?php 

   session_start();
   if(
      empty($_SESSION['login']) and empty($_SESSION['senha']) 
   )
   {
      unset($_SESSION['login']); 
      unset($_SESSION['senha']);
      header('location:acessonegado.php'); 
      exit;
   }

   $logado = $_SESSION['login'];    

?>

Jsfiddle

The index page is the login page.

If login is correct, redirect to questionario_pos_venda.php. Otherwise, redirect to acesso_negado.php.

In the head of questionario_pos_venda.php has verified that the login and password are empty. If you are true, will remarry to acessonegado.php.

I have acesso_negado.php and acessonegado.php because I have to display different information.

  • 2

    This question seems to be discounted because it is a user-specific error that will not contribute to other users of the site

  • Jsfiddle is not opening here (again), but also as I don’t understand why a question about PHP needs it, whatever. I partially disagree with the comment above. Although yes, it is a user-specific problem, solving this problem the Knowledge base would be expanded. However, given the solution presented, I would characterize this problem as a duplicate. Just one reference link.

  • possible duplicate of How to store multiple values in a variable?. That’s not exactly the problem, but it was as close as I could find.

1 answer

-3


I resolved. $_SESSION is coming empty because I forgot the session_start(); at the beginning of questionario_pos_venda.php.

  • Mark your own answer as the best answer. Your question today may be someone else’s tomorrow.

  • Thank you @Brunoaugusto

Browser other questions tagged

You are not signed in. Login or sign up in order to post.