Jump to content

PHP Login system?


MrWeavile

Recommended Posts

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">
<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

Link to comment
https://forums.phpfreaks.com/topic/277947-php-login-system/
Share on other sites

You need to include secured.php into your login.php script, otherwise you never grab the username/password from the form.

Also, your form uses POST as the method, but you're trying to get the variables using GET.

Fix those two problems up and you should start getting some meaningful errors (if there are any), that you can start to debug.

 

Denno

Link to comment
https://forums.phpfreaks.com/topic/277947-php-login-system/#findComment-1429819
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.