I'm new in PHP. As a newbie, I started my first project. I made a login system for my webapp. But there's a problem. When I try to access the index or main page, it asks for login, but when I'm try to access some other page, it doesn't ask me for login.
How can I manage the same restriction for all pages? My login code is here.
<?
$connection=mysql_connect("localhost","admin","");
if(!$connection)
{
die("Database Connection Failed: " . mysql_error());
}
//Select a database to use
$db=mysql_select_db('vss',$connection);
if(!$db)
{
die("Database Selection Failed: " . mysql_error());
}
$username=$_POST['username'];
$password=$_POST['password'];
//
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//
$query="SELECT *FROM user where username='$username'AND password='$password'";
$result=mysql_query($query);
$count=mysql_num_rows($result);
// If result matched $username and $password,table row must be 1 row
if($count==1){
// Register $username, $password and redirect to file "example.php"
session_register("username");
session_register("password");
header("location:http://localhost/vss/main.php");
}
else {
echo "Wrong Username or Password";
}
?>
I just added:$userok=$count;after the line $count==1 Then I added I just added:$userok=$count;after the line $count==1 Then I added Call.php-><?php if($userok!=1); { header("location:localhost/vss/logindo.php";); } ?> I added include(call.php) in the top of restricted pages.But,when i click the button every time it ask for login.How can I make logged user until he press "logout". I added include(call.php) in the top of restricted pages.But,when i click the button every time it ask for login.How can I make logged user until he press "logout".