PDA

View Full Version : Redirecting a user by Header("Location : redirPage.html") not working!


ConfusedOfLife
11-12-2002, 11:02 PM
In my dummy page I wana redirect the user to Congra.html if he answers me correctly, I write :

header("Location : Congra.html");

and I'm also totally aware that I have to write it b4 any html or
php directive that sends the header, or my header would be ignored ( and I remember that I got
some few error messages too when I tried to resend the header after it's already sent! ).
As usual the problem is that it doesn't work! If you wana see the whole code it's as follows
( it's a guess machine! )


<?PHP
$_POST['GuessNo'] = ( isset($_POST['GuessNo']) ) ? ( (int)$_POST['GuessNo'] + 1 ) : ( 0 );
if ( isset($_POST['entGuess']) )
if ( $_POST['entGuess'] > $_POST['toBGuessed'] )
$message = "High Expectations!";
elseif ( $_POST['entGuess'] < $_POST['toBGuessed'] )
$message = "Low Expectations!";
else
{
header("Location : Congra.html");
exit;
}
?>
<script language="javascript">
flag = 0;
function cheat()
{
if ( flag == 0 )
{
setTimeout("cheat();", 1000);
flag++;
}
else if ( flag == 1 )
{
window.status = randNum;
flag++;
setTimeout("cheat();", 1000);
}
else
window.status = "";
}
function randIt()
{
randNum = Math.floor( Math.random() * 100 + 1 );
document.forms[0].toBGuessed.value = randNum;
cheat();
}
</script>
<html>
<body onload="document.forms[0].entGuess.focus(); randIt();">

<center><h1>Guess Machine!</h1></center>
<br />
<h3><?=$message?></h3>
<form action="<? echo $_SERVER[PHP_SELF];?>" method="POST">
<input type="hidden" name="toBGuessed">
<br />
<table border=0>
<tr>
<td>
Guess #
</td>
<td>
<input type="text" name="GuessNo" value="<?=$_POST['GuessNo']?>">
</td>
</tr>
<tr>
<td>
Enter your guess in here :
</td>
<td>
<input type="Text" name="entGuess" value="<?=$_POST['entGuess']?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="Submit" value="Yallah!">
</td>
</tr>
</table>
</form>
</body>
</html>

Nightfire
11-12-2002, 11:23 PM
As usual the problem is that it doesn't work

How does that help? What error are you getting? Are you getting an error? What does it say?

It's also easier if you use the [ php] tags when using php on here

ConfusedOfLife
11-13-2002, 09:10 PM
Well, it just doesn't redirect, I get a blank page and that's all. BTW this is the pure php code and the rest of it was the JS and HTML.


<?PHP
$_POST['GuessNo'] = ( isset($_POST['GuessNo']) ) ? ( (int)$_POST['GuessNo'] + 1 ) : ( 0 );
if ( isset($_POST['entGuess']) )
if ( $_POST['entGuess'] > $_POST['toBGuessed'] )
$message = "High Expectations!";
elseif ( $_POST['entGuess'] < $_POST['toBGuessed'] )
$message = "Low Expectations!";
else
{
header("Location : Congra.html");
exit;
}
?>


Edit : Wow! I can write colorful too! thanx for the tag.

firepages
11-14-2002, 12:15 AM
hi , use

header("Location: Congra.html");
or
header("Location:Congra.html");

the "location:" bit is a HTTP header (well hets converted to one) and has strict rules about its format so I assume thats the problem

ConfusedOfLife
11-15-2002, 01:57 PM
Thanx, it worked!