It is Login Page Code which is accepting Username and Password. But other pages are also opening with URL. Used Session Start Also. Please help me with modifications in code.
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
$con=mysqli_connect('localhost','root','') or die(mysql_error());
mysqli_select_db($con, 'user_registration') or die("cannot select DB");
$query=mysqli_query($con, "SELECT * FROM login WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysqli_num_rows($query);
if($numrows!=0)
{
while($row=mysqli_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: index.php");
}
} else {
echo "Invalid username or password!";
}
} else {
echo "All fields are required!";
}
}
?>