0

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.example.com/site1page");
     }else{
              header('Location: ' . 'http://www.example.com/othersites/&?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?

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I feel retarded right now, can't believe I missed that.
0

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/&?var='.$var,); } ?>

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.