Inhibiting access through the URL

Asked

Viewed 26 times

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 ?

  • Leaving the page as restricted access, access only via login.

  • The way it’s not working ?

  • Yes this, but I wonder if this is a correct way.

  • 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.

  • @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

  • @Guilhermenascimento much better, I’m just creating a list here to find faster.

Show 2 more comments
No answers

Browser other questions tagged

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