User login page not redirecting..
Posted: Mon Jan 21, 2013 4:44 am
I am developing a simple application whereby users will need to log in before having access to the pages. At the point of testing my scripts on live server i discover that the login page is not redirecting to the specified page after successful login. meanwhile it worked perfectly on my local server (WAMP). Please what do i need to do. here is my script.
Code: Select all
<!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>WTListing- Login</title>
</head>
<?php require_once( 'header.php' );
error_reporting(E_ALL - (E_NOTICE + E_WARNING));
include('conection/gen_conn.php' );
include('includes/signup_failure.php' );
?><P><br />
<table width="450" border="½" frame="box" rules="none" align="center" bgcolor="#E9E9E9" bordercolor="#666666">
<tr>
<td align="center">
<?php
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM wtl_reg_posters WHERE username = '$username'")
or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
header('Location: login.php');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT username, password FROM wtl_reg_posters WHERE username = '".trim($_POST['username'])."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die($failure_username_notexist);
}
while($info = mysql_fetch_array( $check )) {
$password = md5($_POST['pass']);
$password = stripslashes($password);
$info['password'] = stripslashes($info['password']);
$password_md5= substr($password, 0, 15);
//gives error if the password is wrong
if ($password_md5 != $info['password']) {
die($failure_password_nomatch);
} else {
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header("Location: add_posting.php");
}
}// End of while loop
}//eEnd of if for form submission
else {
// if they are not logged in
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <br /><br />
<table border="½" bgcolor="#E9E9E9" class="selectfirst" frame="void" rules="none">
<tr>
<td><font color="#006699">Username:</font></td>
<td><input type="text" name="username" maxlength="40" class="inputreg"></td>
</tr>
<tr>
<td><font color="#006699">Password:</font></td>
<td><input type="password" name="pass" maxlength="50" class="inputreg">
</td>
</tr>
<tr>
<td align="left"><br /><input type="submit" name="submit" value="Login" class="selectfirst"></td>
<td align="right"><br /><strong>
<font face="Vani" color="#993300" size="2">Don't have an account?</font> <a href="signup.php">Signup Now</a></strong>
</td>
</tr>
</table>
</form><div align="left">
<h3>
<a href="password_reset.php">Forgot your Passoword?</a><br />
<a href="user_reset.php">Forgot your Username?</a></h3></div>
<?php
}
?>
</td>
</tr>
</table></P><br />
<?php
include('footer.php');
?>
</html>