DWood
03-04-2002, 05:09 PM
Since most of you are rather experienced in PHP, I figured you might know why this doesn't work. It above the HTML tag of all protected pages, and the pages are protected despite whether the password is correct or incorrect. Also, I want to have it as an include file but when I tried that the invalidlogin page was displayed followed by the protected page :-(... why would the exit command not stop the loading? Please help me out. If you want to see the result visit http://crosse5.com/members/dying.php and use test as the username and pass as the password. Thanks in advance.....
Or if you know of any working ones that don't have advertisements on them please let me know.
<?php
if (action == "login") {
if ((isset($PHP_AUTH_USER)) && (isset($PHP_AUTH_PW))) {
// Connect to MySQL
mysql_connect('localhost', 'user', 'pwpw')
or die ('Unable to connect to server.');
// Select database on MySQL server
mysql_select_db('database')
or die ('Unable to select database.');
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql)
or die ('Unable to execute query.');
// Get number of rows in $result.
$num = mysql_numrows($result);
if ($num != 0)
{
$auth = true;
setcookie("id","$PHP_AUTH_USER",time()+14400,"/",".crosse5.com",0);
setcookie("pass","$PHP_AUTH_PW",time()+14400 ,"/",".crosse5.com",0);
} else {
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
} else {
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
} elseif (action == "logout") {
setcookie("id","",time()+14400,"/",".crosse5.com",0);
setcookie("pass","",time()+14400,"/",".crosse5.com",0);
include ('http://crosse5.com/members/invalidlogin.php');
exit();
} else {
if ((isset($id)) && (isset($pass))) {
$PHP_AUTH_USER = $HTTP_COOKIE_VARS["id"];
$PHP_AUTH_PW = $HTTP_COOKIE_VARS["pass"];
// Connect to MySQL
mysql_connect('localhost', 'user', 'pwpw')
or die ('Unable to connect to server.');
// Select database on MySQL server
mysql_select_db('database')
or die ('Unable to select database.');
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql)
or die ('Unable to execute query.');
// Get number of rows in $result.
$num = mysql_numrows($result);
if ($num != 0) {
$auth = true;
// A matching row was found - the user is authenticated.
setcookie("id","$PHP_AUTH_USER",time()+14400,"/",".crosse5.com",0);
setcookie("pass","$PHP_AUTH_PW",time()+14400 ,"/",".crosse5.com",0);
} else {
$auth = false;
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
}
else {
$auth = false;
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
}
?>
Or if you know of any working ones that don't have advertisements on them please let me know.
<?php
if (action == "login") {
if ((isset($PHP_AUTH_USER)) && (isset($PHP_AUTH_PW))) {
// Connect to MySQL
mysql_connect('localhost', 'user', 'pwpw')
or die ('Unable to connect to server.');
// Select database on MySQL server
mysql_select_db('database')
or die ('Unable to select database.');
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql)
or die ('Unable to execute query.');
// Get number of rows in $result.
$num = mysql_numrows($result);
if ($num != 0)
{
$auth = true;
setcookie("id","$PHP_AUTH_USER",time()+14400,"/",".crosse5.com",0);
setcookie("pass","$PHP_AUTH_PW",time()+14400 ,"/",".crosse5.com",0);
} else {
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
} else {
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
} elseif (action == "logout") {
setcookie("id","",time()+14400,"/",".crosse5.com",0);
setcookie("pass","",time()+14400,"/",".crosse5.com",0);
include ('http://crosse5.com/members/invalidlogin.php');
exit();
} else {
if ((isset($id)) && (isset($pass))) {
$PHP_AUTH_USER = $HTTP_COOKIE_VARS["id"];
$PHP_AUTH_PW = $HTTP_COOKIE_VARS["pass"];
// Connect to MySQL
mysql_connect('localhost', 'user', 'pwpw')
or die ('Unable to connect to server.');
// Select database on MySQL server
mysql_select_db('database')
or die ('Unable to select database.');
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql)
or die ('Unable to execute query.');
// Get number of rows in $result.
$num = mysql_numrows($result);
if ($num != 0) {
$auth = true;
// A matching row was found - the user is authenticated.
setcookie("id","$PHP_AUTH_USER",time()+14400,"/",".crosse5.com",0);
setcookie("pass","$PHP_AUTH_PW",time()+14400 ,"/",".crosse5.com",0);
} else {
$auth = false;
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
}
else {
$auth = false;
include ('http://crosse5.com/members/invalidlogin.php');
exit();
}
}
?>
