Jump to content

Archived

This topic is now archived and is closed to further replies.

Alanmoss

Header Location

Recommended Posts

Hi , Can someone tell me why this script redirects
<?
$var = 3;
if($var = 2)
{
header ("Location: page2.php");
exit();
}
else
{
echo'
<p>Page 1 end</p>';
}
?>

Thanks, Alan.

Share this post


Link to post
Share on other sites
Because you actually wanted to test $var using the equality operator (==) not the assignment operator (=), and the assignment is always true. Try this instead:

[code]if ($var==2) { do whatever ... [/code]

Share this post


Link to post
Share on other sites
Thanks very much and it was a mistake , i did not mean to post it twice but i didn't think it was posted firts time .

Thanks, alan

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.