I use the following as an include in every page of a site (this requires php4 and a user_tbl with id, login_name, and password fields). You could also add crypting to the password to secure it.
-- begin snip ---
<?php
/
File: auth.inc.php
Description: prompts user for http authentication and checks
input against MySQL
/
$auth="false";
session_start();
while ($auth=="false")
{
if (!isset($PHP_AUTH_USER))
{
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="Secure Area"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
} else {
$server = "localhost";
$database = "dbname";
$dbuser = "dbuser";
$dbpassword = "password";
$conn=mysql_connect($server, $dbuser, $dbpassword);
mysql_select_db($database);
$password=$PHP_AUTH_PW;
// Formulate the query
$sql = "SELECT
FROM user_tbl
WHERE
login_name = '$PHP_AUTH_USER' AND
password = '$password'";
// Execute the query and put results in $result
$result = mysql_query( $sql );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 )
{
/ echo "<P>You have entered this username: $PHP_AUTH_USER<br>
You have entered this password: $PHP_AUTH_PW<br>"; */
$auth="true";
$login_name=$PHP_AUTH_USER;
session_register(auth);
session_register(login_name);
} else {
// if we don't unset the $PHP_AUTH_USER variable we will while loop forever
unset ($PHP_AUTH_USER);
}
}
}
?>
-- end snip ---
Brian Snipes
Chess wrote:
If I want to have a login.php
thang..
And you need to login in order
to get to a specific page.
I can do this..
However, if a person knows the
direct name of this as called
"secured php file".
Then he can just simply
go through my login page
and direct to that page.
What script shall I put on
my "secured" page in order to
let noone go around my login page?
/Chess