Hey guys...
I've just added password protection to the CMS that I've been working on forever. It works perfectly locally, but when I upload it to the server, it doesn't!
I'm not quite sure what's happening. Whenever I type any username or password combo (whether it's valid or not), it redirects to web root.
Again, this all works locally. I'm running PHP 5.2.4 locally and the server is running 5.2.1.
PHP Code:<?php
session_start();
// Open Database
include_once('php/config.php');
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
$admin_user_name = $HTTP_POST_VARS['u_name'];
$query = "SELECT * FROM ulist WHERE uname='$admin_user_name' ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$admin_password = $row['pword'];
}
//you can change the username and password by changing the above two strings
if (!isset($HTTP_SESSION_VARS['user'])) {
if(isset($HTTP_POST_VARS['u_name']))
$u_name = $HTTP_POST_VARS['u_name'];
if(isset($HTTP_POST_VARS['u_password']))
$u_password = md5($HTTP_POST_VARS['u_password']);
if(!isset($u_name)) {
?>
<!-- FORM -->
<?php
exit;
}
else {
function login_error($host,$php_self) {
// ERROR MESSAGE
session_unregister("adb_password");
session_unregister("user");
exit;
}
$user_checked_passed = false;
if(isset($HTTP_SESSION_VARS['adb_password'])) {
$adb_session_password = $HTTP_SESSION_VARS['adb_password'];
if($admin_password != $adb_session_password)
login_error($HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF']);
else {
$user_checked_passed = true;
}
}
if($user_checked_passed == false) {
if(strlen($u_name)< 2)
login_error($HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF']);
if($admin_user_name != $u_name) //if username not correct
login_error($HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF']);
if(isset($admin_password)) {
if($admin_password == $u_password) {
session_register("adb_password");
session_register("user");
$adb_password = $admin_password;
$user = $u_name;
}
else { //password in-correct
login_error($HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF']);
}
}
else {
login_error($HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF']);
}
$domain = $_SERVER['HTTP_HOST'];
$page_location = "http://" . $domain . $_SERVER["PHP_SELF"];
echo $page_location;
}
}
}
?>



Reply With Quote
(:

Bookmarks