Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.