Re: Re: setting up a user login with PHP

From: Date: Mon, 10 Dec 2001 19:46:32 +0000
Subject: Re: Re: setting up a user login with PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-77226@lists.php.net to get a copy of this message
or you could use: http://phpclasses.upperdesign.com/browse.html/package/288 py At 01:08 PM 12/10/01 -0500, Jeremy Reed wrote:
The easiest way is to use cookies. =========CODE============ <?php require 'auth_functions.php'; if (authenticateUser($form_username, $form_password)){ setcookie("cookie_passwd",$form_password); setcookie("cookie_user",$form_username); header("Location:http://$SERVER/index2.php"); exit(); } else { header("Location:http://$SERVER/error.html"); } ?> This code takes in input from a form as simple as this: <form name="form1" method="post" action="index.php"> Login: <input type="text" name="form_username"><br> Password: <input type="password" name="form_password"> <br> <input type="submit" name="Submit" value="Login"> </form> Checks it against the database values using the function 'authenticateUser', returns TRUE or FALSE. If true, sends the user onto the correct page, if false, sends them to some error page. Now, in each other file, you'll need to check the cookies. The values for the cookies are sent automatically by the user's browser. In this particular examples, the cookie variables are named '$cookie_user' and '$cookie_passwd'. You can see in the example how those are set. You will check the cookies using the exact same 'authenticateUser' function. Except in these files, you will use the cookie values as the parameters to the function instead of the form values. Hope this helps. Best regards, Jeremy Reed "Mark Ward" <WardMa@ott.nrc.ca> wrote in message news:9258C238472FD411AA860004AC369AF90EDAAC32@nrcmrdex1.imsb.nrc.ca... I've got a mySQL database with usernames and passwords. What's the best way to allow authorized users to enter my site? I'm having some problems using the forms properly, they've always been my achilles heel when it comes to web programming. Any help is appreciated. Mark Ward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#77226) next »