Hi guys I am trying to make a password protected page just testing it out on my local machine. I am still in the progress of learning php. But I am stuck right now. First of all this is the code that I am using.
I also made a text file with 6 login's and I am using this code to retrieve them
THIS IS THE PAGE THAT CHECKS IF THE LOGIN INFO IS CORRECT.
Code: Select all
<?php
// Retrieving username and pass
session_start();
$u = $_POST["username"];
$p = $_POST["password"];
//declaring user and pass as global
$_SESSION["u"]=$u;
$_SESSION["p"]=$p;
// choping so no spaces
$x=chop($user_name[0]);
$x=chop($user_name[1]);
$x=chop($user_name[2]);
$x=chop($user_name[3]);
$x=chop($user_name[4]);
$x=chop($user_name[5]);
//gets the info from this textfile
$user_name = file("login.txt");
// checks if the login is correct
$found=0;
for ($x=0; $x<count($u_list); $x++)
{
if(($u==$u_list[$x]) && ($p==$p_list[$x]))
{
$found=1;
}
}
?>
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Password Protected Page</title>
</head>
<body onLoad="JavaScript:document.form1.username.focus()">
<h1>Welcome to Secure Info Vault</h1>
<form method="post" action="check_login.php" name="form1">
<p>USERNAME:<input type="text" name="username" /></p>
<p>PASSWORD:<input type="password" name="password" /></p>
<input type="submit" name="login" value="Login" />
</form>
</body>
</html>Thank You
Gary