Ayush Chaurasia Ayush Chaurasia - 6 months ago 23
PHP Question

Header() in php not working

I have developed a php web app which makes use of the

function of
. For instance, when a user is logged in, the website should redirect to homepage. This works perfectly while testing the site on my local computer using
server , but when I try to access the site using its domain name, it does not redirect to homepage .

This is the code I have used :

$query = "select * from user where email= '$email' and pass= '$pass'";
$result = mysql_query($query);

if(mysql_num_rows($result) != 0) {
$row = mysql_fetch_row($result);
$_SESSION['user'] = $row[0];
$_SESSION['email'] = $row[1];
$_SESSION['pass'] = $row[2];
$_SESSION['id'] = $row[3];
$_SESSION['last_name'] = $row[4];
$_SESSION['dp'] = $row[5];

header("Location: index.php");
} else
$wrong_cred = true;

if($wrong_cred) {
echo("<div class='pageBegin'><p><h1>Wrong User name or Password></h1></p></div>");


Use @obstart or try to use Java Script

put your obstart(); into your top of the page

if ((isset($_POST['cancel'])) && ($_POST['cancel'] == 'cancel'))
    header('Location: page1.php');

If you use Javascript Use window.location.href

window.location.href example:

 if ((isset($_POST['cancel'])) && ($_POST['cancel'] == 'cancel'))
        echo "<script type='text/javascript'>window.location.href = 'page1.php';</script>"