RE: [PHP] Connection Form
| From: | Don Read | Date: | Sat, 04 Nov 2000 01:35:43 +0000 |
| Subject: | RE: [PHP] Connection Form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23669@lists.php.net to get a copy of this message | ||
On 03-Nov-00 Jon wrote:
> I need to create a "connection form" for my site and I want the password to
> be checked against a database. After being validated by the database I need
> to save username&password in global variables so in every other page of my
> site I would be able to check permisions and so reject the non-validated
> users. Is this posible using php? Is there avaible some lines of sample code
> to do this?
>
in 'my_secure.php'
-------
define("SITEHOME", "http://www.myhome.org/");
function authuser($realm) {
global $PHP_AUTH_USER, $PHP_AUTH_PW;
if (! (isset($PHP_AUTH_USER)) ) {
Header("WWW-authenticate: basic realm=\"$realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "\n\n<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;
URL=".SITEHOME."\">";
exit;
}
if (! (checklogin($PHP_AUTH_USER, $PHP_AUTH_PW, $realm)) ) {
Header("WWW-authenticate: basic realm=\"$realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "\n\n<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;
URL=".SITEHOME."\">";
echo "Invalid login";
exit;
}
}
you'll need to write the checklogin() function to validate the user
& password (& $realm) returning true if validated , false otherwise.
Then at the top of each of your pages:
<?php
require('my_secure.php');
authuser(My_realm');
...
Regards,
--
Don Read dread@texas.net
There are old sailors, and there are foolish
sailors; but damn few old foolish sailors.
---------------------------------------------