Hi
I created a login page and register a session with username, however, how can I set the loginok.php page must be login successfully and be able to view? Currently, I can view the loginok.php without login. How should I set the loginok.php code to prevent it?
<?php
session_start();
session_destroy();
$Login=$_POST['login'];
if($Login){
$username=$_POST['username'];
$password=$_POST['password'];
// Connect database.
$conn = mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db ($dbname, $conn);
// Check matching of username and password.
$result=mysql_query("select username, password from account where username='$username' and password='$password'");
if(mysql_num_rows($result)!='0')
{ // If match.
session_register("username");
header("location: loginok.php");
exit;
}else{ // If not match.
header("location: loginfail.php");
exit;
}
}
?>