Basically I’m grabbing a variable from the url and I need to send the user to custom pages based on what state they fill in. i.e. if it’s one of the coverred states, they’ll get sent to custom pages…but if it’s any other state they get sent to the standard one.
I’m guessing it’s just a simple if statement with an else…but for some reason I can’t get it to work properly.
<?php
$state = urlencode($_GET['state']);
if ($state=="california"){$link = "http://website.com/page1";}
else if ($state=="new york"){$link = "http://website.com/page2";}
else if ($state=="ohio"){$link = "http://website.com/page3";}
else {$link = "http://website.com/default";}
header("Location: $link");
?>
Is this right or should I be doing something else?
You don’t need urlencode function to encode what you “GET”, unless you sent the string in the url has been encoded. However, in that case you would need the urldecode function, still not urlencode.
So your code should be like this:
Also, check the ‘state’ in the url. Did you receive the correct string that you need? Try to echo $state, and see what you get.