tags:

views:

466

answers:

3

I have visitors coming to my site from 5 seperate sources, each one sends a variable in the url based on where its from, in the event these sources sends visitors I want to send them to a seperate page thats more relevant to the user

<?php
$var = $_GET["var"];


if( $var='site1')
{
header('Location: ' . "http://www.mysite.com/site1page");
}
else
{
header('Location: ' . 'http://www.mysite.com/othersites/&amp;?var='.$var,);
}
?>

however no matter what $var comes in has its going to the first header location(site1page) Can anyone explain why this is happening?

A: 

Your code is doing assignment (the single equal sign). You want an equality test (double equals sign):

<?php if( $var=='site1') { header('Location: ' . "http://www.mysite.com/site1page"); } else { header('Location: ' . 'http://www.mysite.com/othersites/&amp;?var='.$var,); } ?>
Tony Miller
+4  A: 

If that code is the actual code you are running - it is because you are using "=", the assignment operation instead of "==" the comparison operator. PHP lets you bite yourself this way without any sort of warning.

pivotal
Thanks I feel retarded right now, can't believe I missed that.
A: 

Additionally, I think that comma in the second header line is going to give you a parse error.

Citizen