Jump to content


Photo

Header Location


  • Please log in to reply
2 replies to this topic

#1 Alanmoss

Alanmoss
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 11 June 2006 - 08:08 PM

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.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 June 2006 - 08:14 PM

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

if ($var==2) { do whatever ...

Legend has it that reading the manual never killed anyone.
My site

#3 Alanmoss

Alanmoss
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 11 June 2006 - 08:26 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users