If you wanted to check for more than one username/password set, then extend
this line

 if ($userid == "somename" && $password == "somepassword") {

to something like

 if (($userid == "somename1" && $password == "somepassword1") ||
     ($userid == "somename2" && $password == "somepassword2") ||
     ($userid == "somename3" && $password == "somepassword3")) {

Martin

-----Original Message-----
From: Gaylen Fraley [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 26, 2001 2:01 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: authentication help


Here would be one of many ways.  This assumes that login.php and index.php
are in the same directory.

login.php

<?
if (isset($userid)||isset($password)) {
 if ($userid == "somename" && $password == "somepassword") {
  echo "YAY! You did it!";
  exit;
 }
 header("Location: index.php");
 exit;
}
?>
<html>
<body>
<form action="<?=$PHP_SELF?>" method=post>
<table align=center border=2>
<tr><td>User  <td><input name=userid></tr>
<tr><td>Password  <td><input type=password name=password></tr>
<tr><td colspan=2 align=center><input type=submit value=Submit>
</form>
</body>
</table>
</html>

--
Gaylen
[EMAIL PROTECTED]
http://www.gaylenandmargie.com
PHP KISGB v2.1 Guestbook http://www.gaylenandmargie.com/phpwebsite

"Norman Zhang" <[EMAIL PROTECTED]> wrote in message
001701c15cd8$a7acb710$[EMAIL PROTECTED]">news:001701c15cd8$a7acb710$[EMAIL PROTECTED]...
> Hi,
>
> Would someone please give me a few pointers on how to generate a simple
PHP
> to check for user's name and password before directing to a directory?
>
> e.g., I have a index.php with a form where I have action="login.php". How
> would I write login.php to check username and password if I have them hard
> coded in login.php and if authentication fails the user is directed back
to
> index.php? Is this safe?
>
> Regards,
> Norman
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to