HTML Form
Enter Username: Enter Password: ======================================== [php]<?php session_start(); $host = "localhost"; $user = "root"; $db_name= "customer"; $pass= ""; $tbl = "customer_details";$link = mysql_connect("$host", “$user”, “$pass”)or die(“Cannot connect”);
mysql_select_db("$db_name")or die(“Not selected”);
// checkLogin.php
if(isset($_POST[“login”])) {
$usernameLogin = ($_POST[‘user’]);
$passwordLogin = ($_POST[‘pass’]);
$sql=“SELECT * FROM $tableName WHERE username=’$usernameLogin’ and password=’$passwordLogin”;
$result=mysql_query($sql,$link) or die(“NO MATCHES”);
$row = mysql_num_rows($result);
$database_password = $row[‘password’];
}
if ($database_password = $passwordLogin)
{ $_SESSION[‘Authenticated’] = 1;
}
else { $_SESSION[‘Authenticated’] = 0; }
header(“location:customerProtected.php”);
?>[/php]
===============================================
Protected Page [php]<?php
session_start();
?>
Protected content
<?php }else{ ?>To view protected content you must login.
<?php } ?>[/php]===============================================