I want to use one URL to redirect users to various outgoing URLs. For example http://example.com/out.php?ofr=2 where ofr will refer to the appropriate URL the user should be redirected to.
I have the following php code for out.php
Is this acceptable, or is there a more efficient way to accomplish this (assuming there were 10 or so different URLs in the below script)?
<?php
$ofr = $_GET['ofr'];
if ($ofr == 1) {
header('location: http://google.com');
}
elseif ($ofr == 2) {
header('location: http://yahoo.com');
}
else {
header('location: http://msn.com');
}
?>
Edit: Looking at switch statements as suggested, I believe it would look like:
$ofr = $_GET['ofr'];
switch ($ofr){
case 1: header('location: http://example_1.com');
break;
case 2: header('location: http://example_2.com');
break;
default: header('location: http://example_2.com');
break;
}
Does that look correct? Thanks!
if-statements. (btw:switch-statements do exist)