I require a very lightweight login and password facility for about 5 people to gain access to a back office web page with relevant information for them. I have found this flat file example code at http://www.ehow.com/how_6587681_crea...using-php.html. There seems to be something with this ("myfile.txt\",\"r\") causing a break in the code at about line 6.
Assuming that the processor code can be fixed I should progress as follows :
1. Set up a myfile.txt to record the required Usernames and Passwords
2. Set up login.html to position the login form. Should this be saved with a .php extension?
3. Set up the form handler processor.php
Any guidance greatly appreciated.
PHP Code:
<?php
function CheckLogin($uid,$pw)
{
// set the login variable to false
$valid=false
// open the flat file and set it to the beginning
$f = fopen ("myfile.txt\",\"r\")
rewind($pfile)
// check all lines in flat file database
while (!feof($f))
{
// get the data from a single line
$line = fgets($f)
// assign the user name and password to an array variable
$log = explode(',', $line)
// check the user name against the current line in the flat file
if ($log[0] == $uid)
{
// the user exists so check the password
if (log[1] == $pw){
// the password is valid so set the login variable to true
$valid=true
}
}
}
// if the login variable is true then return true, otherwise return false
if($valid=true){
return=true
}else{
return=false
}
}
?>
<?php
// call the check login function with the fields entered into the login form
if(!CheckLogin($_POST['username'],$_POST=['password'])
{
// the login is false so redirect the user to the login page
header('Location: login.php')
// the login information is correct so load the page and end the PHP script
}else{
?>
HTML Code:
<form name="formname" method="post" action="processor.php">
<br /><br />
Username :<input type="text" name="username">
<br /><br />
Password :<input type="text" name="password"><br /><br />
<input type="submit" name="Submit" value="Submit">
</form>
Bookmarks