I am working on a PHP task. I have two pages. On e is for login and after successfully login, user will redirect to next page. But if someone enters URL of page2 in URL bar without going to page to through login page. They can, I want to restrict this. But have no idea, how... here's my code of login page.
<html>
<body>
<div id="content">
<h3>Login to AdminUpdate</h3>
<form id="login" action="" method="post">
<p>
<label for="userid">UserID:</label>
<input type="text" name="Name" id="UserID"/>
</p>
<p>
<label for="PIN">PIN:</label>
<input type="password" name="password" id="PIN" />
</p>
<p>
<input type="submit" name="btnSend" value="Login" class="submit_button" />
</p>
</form>
<td> </td>
<div id="wrap">
<!-- start PHP code -->
<?php
$conn = mysqli_connect("localhost", "root", "", "tnz");
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if(!empty($_POST['Name']) && (!empty($_POST['password']))){
$UserName = $_POST['Name'];
$PIN = $_POST['password'];
$search = mysqli_query($conn,"SELECT * FROM login WHERE Name='".$UserName."' AND password='".$PIN."'") or die(mysql_error());
$match = mysqli_num_rows($search);
if($match > 0){
header('Location: AdminUpdates.php');
}else{
echo 'LogIn Failed';
header('Location: AdminCheck.php');
}
}
?>
</div>
</div>
</body>
</html>