Creating a script that Authenticates users
From: JENNA (assertec_at_bigpond.com)
Date: 10/27/04
- Previous message: Ralph Krausse: "XSLT on PHP 4.3.4"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Oct 2004 19:46:35 -0700
Hi all,
I'm having real problems trying to create an authentication script
that works.
I have a text file that lists usernames and passwords separated by a
colon like this for a simple example:
jenna:124
fred:234
harry:777
etc.. etc
I have saved this file as: Authorization.txt
My php file actually reads like below but when I run it, it seems to
only check the first username and password in the Authorization.txt
(i.e jenna:124 in this case) and doesn't seem to check the rest. The
php file gets the username and password that need to be authenticated
from a html document.
Does anyone have any code that will do this for me, as I've tried
messing around with this for ages, and I'm not getting anywhere.
Thanks so much for any help with this.
Regards Jenna
-------------------------
<html>
<head><H1></H1></head>
<body>
<?php
$auth = false; //assumes the user is not authenticated
$filename = 'Authorization.txt';
$fp = fopen($filename, 'r');
$file_contents = fread($fp, filesize( $filename ));
fclose($fp);
$_GET['Username']; //receives the username from the html document
$_GET['Password']; //receives the password from the html document
$ContentsArray = explode("\r\n", $file_contents);
foreach($ContentsArray As $ArrayIndex)
{
list($UsernameInFile, $PasswordInFile) = explode(":",
$ArrayIndex);
if(($Username == "$PHP_AUTH_USER") && ($Password == "$PHP_AUTH_PW"))
{
$auth = true;
break;
}
}
if(! $auth)
{
echo 'You are unathorized;
exit;
}
else
{
echo 'You are authorized!';
}
?>
</body>
</html>
- Previous message: Ralph Krausse: "XSLT on PHP 4.3.4"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|