Forum Moderators: coopster

Message Too Old, No Replies

Problem re-directing after login succesfull!

         

dwighty

9:33 am on Nov 17, 2005 (gmt 0)

10+ Year Member



Hello all,

I would imagine there is a very easy answer to this but at the moment i cant see it. Below is part of my code that i am having trouble with. It basically does not re-direct the user to the main.php page. If i replace the

header("Location: main.php");
with
echo "Welcome to Secure Area.";
It shows the Welcome to Secure Area.

*************************CODE**********************

if($submit)
{
$user = $_POST['user'];
$pass = $_POST['pass'];

if($user == "$data[admin_user]" && md5($pass) == "$data[admin_pass]")
{
header("Location: main.php");
}
else
$check=1;

}
?>
<form action="<?php echo $PHP_SELF?>" method="post">
Username:<br />
<input type="text" name="user" size="20"><br /><br />
Password:<br />
<input type="password" name="pass"><br /><br />
<input type="submit" name="submit" value="Log in">
</form>
<?php
if($check == 1)
echo 'There has been an error logging you in, please try again. If this problem persists please contact your <a href="****" title="">administrator</a>.';
?>

THanks in advance

IamStang

11:59 am on Nov 17, 2005 (gmt 0)

10+ Year Member



This was taken directly from the PHP: header - Manual [us3.php.net] and would be a good starting point to fixing your code.
"Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

I hope it helps!
IamStang

PeteM

1:05 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



This also catches people out....

"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP."

dwighty

3:12 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



PeteM

Thanks a lot, thats all i needed to do. Every other script i write has this at the start...oh well.

Thanks

Dwighty