Well, I have been going around and around trying to make my login script (which has worked in the past) work. I finally got it down to one problem with some help from others. The problem now is that when I login on this page: http://resonant-media.com/client_work/cms/cms/login.php, my login script does not read the sessions, but if I login here: http://www.resonant-media.com/client_work/cms/cms/login.php, my login script reads the sessions.
I also set up a page to make sure the sessions are set. If I login on the page with www. in front of the url, I can see the variables set from my session reader only if I put www. in front of the url. It also does the same thing when I do not put in www., just in the opposite way (login without www. and read without www.).
I have never had this problem before and can't think of any reason for it. Anyone have any ideas?
Here is my login page code:
(login.inc.php)
PHP Code:
<?php
########## If Login Hit ##########
if ($_POST['login']) {
$user = mysql_real_escape_string($_POST['user']);
$pass = md5($_POST['pass']);
// Get User Data
$check = mysql_query("SELECT * FROM `admins` WHERE user = '$user'") or die ("Error Checking Username! \n<br />\n" .mysql_error());
$u = mysql_fetch_array($check);
$chk = mysql_num_rows($check);
//
// Check Fields
if (!$user || !$pass) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Please fill in all fields!</div>'); }
//
// Check User
else if ($chk < 1) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Invalid username!</div>'); }
//
// Check Password
else if ($u['pass'] !== $pass) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Invalid password!</div>'); }
//
// If Everything Checks Out
else {
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
$_SESSION['site'] = $siteName;
echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">Welcome '.$_SESSION['user'].', you are now logged in!</div>');
}
}
########## If Login Not Hit ##########
if (!$_POST['login']) { ?>
<div class="message">Admin Login</div> <br /><br />
<!-- Login Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="250" align="center">
<tr>
<td>Username:</td>
<td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pass" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Login" /></td>
</tr>
</table>
</form>
<!-- /Login Form -->
<? }
?>
That page is called within this page:
(login.php)
PHP Code:
<?php @session_start(); require('config.php'); chkBan(); chkLogin(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $m['title'] ?> | Admin Panel</title>
<link rel="stylesheet" href="main-style.css" type="text/css" />
</head>
<body>
<div id="frame">
<div id="border">
<div id="top">
<div class="t_txt"><?php echo $siteName ?></div>
</div>
<div id="left">
<div class="s_title">Navigation</div>
<?php require('includes/nav.inc.php'); ?>
</div>
<div id="main">
<div class="spacer"><?php require('login.inc.php'); ?></div>
</div>
<div id="footer">
<div id="footer_txt"><?php echo $m['copyright'] ?></div>
</div>
</div>
</div>
</body>
</html>
And here is the chkLogin() function:
PHP Code:
function chkLogin($loginRedirect){if(!isset($_SESSION['user'])){header("Location:$loginRedirect");}}
Any ideas, thanks
Bookmarks