1
I want to know if this way is correct:
inhibited page
<?php
if (!isset($_SESSION)) session_start();
if (!isset($_SESSION['usuario'])) {
session_destroy();
header("Location: login.php"); exit;
}
?>
<html>
<head>
<title>Doidao</title>
</head>
<body>
<h1> HELLO </h1>
</body>
</html>
code that checks the login
<?php
include_once("conexao.php");
session_start();
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$result = "SELECT * FROM `usuarios` WHERE `usuario` = '$usuario' AND `senha`= '$senha'";
$resultado = mysqli_query($conn, $result);
if(mysqli_num_rows($resultado) > 0 )
{
$_SESSION['usuario'] = $usuario;
$_SESSION['senha'] = $senha;
echo "<script>alert('Seja bem-vindo $usuario, conhecimento não é crime. ATT: Marcos.');</script>";
echo'<script>window.location="index.php";</script>';
}
else{
unset ($_SESSION['usuario']);
unset ($_SESSION['senha']);
echo "<script>alert('Login ou senha incorretos !');</script>";
echo'<script>window.location="login.php";</script>';
}
?>
What do you mean, when you say:
Inibindo acesso pela URL
?– NoobSaibot
Leaving the page as restricted access, access only via login.
– Marcos A. Massini
The way it’s not working ?
– NoobSaibot
Yes this, but I wonder if this is a correct way.
– Marcos A. Massini
So here’s the answer you’re looking for: Block PHP page access through the URL | Doubt about PHP page security... I will signal to close this question.
– NoobSaibot
@Wéllingthonm.Souza I think this would be better https://answall.com/questions/3571/qual-a-bestmaneira-de-cria-um-system-de-login-com-php
– Guilherme Nascimento
@Guilhermenascimento much better, I’m just creating a list here to find faster.
– NoobSaibot