I'm trying to make a login system using two PHP scripts, a html and a text file. The html should link to the login.php which should get a name from the text file with all the usernames and passwords, then allow entry if correct while setting a cookie. The four files are called:
login.html
login.php
secured.php
user.txt
The code for the html is:
<!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>Login</title>
</head>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
The code for the login.php is:
<?php
while(!feof($fileHandle)) {
$Data=fgets($fileHandle);
$user=explode("|",$data);
$user[0];
$user[1];
$name=trim($user[0]);
$pass=trim($user[1]);
}
if($usern==$user && $passw==$password)
{
setcookie("uname",$usern);
header("Location:home.php");
exit();
}
?>
The code for the secured.php is:
<?php
$usern=$_GET['username'];
$passw=$_GET['password'];
$fileHandle=fopen('user.txt','r');
?>
I uploaded all four files to my local server then ran the html off that server by connecting to it directly within the URL bar. The login will just stay there not loading anything. I'll upload the files too.
login.html
login.php
secured.php
user.txt