I am using a login area in my website in order the user to login to the website and be able to buy items online.I want when the user logins and verifies the identity to redirect to another page (page basket) in order the user to see his items. I have created the login page and verifyies the identity however my problem is that does not redirect the user to the next page it just reloads the same page.In order to redirect the user i use the function header after the verification of the user. I will post here the code and I would really appreciate your help.
HTML Code:
<table width="490" border="0" align="center" cellpadding="0" cellspacing="0"><tr><th width="293" valign="top" class="descriptiontitle" scope="col"><div align="left">Please fill in the details to login </div></th></tr><tr><th valign="top" class="descriptiontitle" scope="col"> </th></tr><tr><th valign="top" scope="col"><form name="login" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"><table width="185" border="0" align="center"><tr><td><label><span class="body">Username:</span></label></td><td><input name="user" type="text" class="body"></td></tr><tr><td><label><span class="body">Password</span>:</label></td><td><input name="pass" type="password" class="body"></td></tr><tr><td> </td><td><input name="submit" type="submit" class="body" value="Login"></td></tr></table></form></th></tr><tr><th valign="top" scope="col">
l
PHP Code:
<table width="185" align="center"> <tr> <td width="756"> <? if (isset($_POST['submit'])) {//If submit button has been clicked
//First check if there is data and is valid
//check for the username if (empty($_POST['user])) { $user=FALSE; echo '<p class=\'errorregister\'>You forgot to enter your username</p>'; }else { $user=$_POST['user']; }
if (empty($_POST['pass'])) { $pass=FALSE; echo '<p class=\'errorregister\'>You forgot to enter your password</p>'; }else { $pass=$_POST['pass']; }
if ($user && $pass){
$query = "SELECT * FROM Customer WHERE user= '$user' and pass=PASSWORD('$pass')"; $result = @mysql_query($query); $row = mysql_fetch_array($result);
if ($row){ $_SESSION['user']=$row['user']; $_SESSION['pass']=$row['pass']; ob_end_clean();//Delete the buffer echo "welcome"; header ("Location: http://domain.co.uk/basket.php"); exit();
}else { echo '<p class=\'errorregister\'>Your username and password do not match</p>'; } mysql_close();
} else { //if username and password had problem echo '<p class=\'errorregister\'>Please try again'; }
}//end of submit conditional
?> </td> </tr> </table>
HTML Code:
</th></tr><tr><th valign="top" scope="col"><div align="left" class="body"><span class="confirm">Note:</span> if you don't have an account please <a href="regi.php">register</a></div></th></tr></table>
My understanding is that once you have written anything to the page (which is converted to HTML) then the headers are automatically sent, and you can't send them twice.
Have you tried using a META refresh or a javascript redirect??