Forum Moderators: coopster
Parse error: parse error, unexpected ':' in /usr/www/mysite/jump.php on line 3
Here is the script I have.
<?phpif ($id == "") {$link = http://www.mysite.com;} //Default Blank
if ($id == "1") {$link = http://www.yahoo.com;} // COMMENT
if ($id == "2") {$link = http://www.google.com;} // COMMENT
if ($id == "3") {$link = http://www.webmasterworld.com;} // COMMENT
header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header
header("Location: $link"); // Jump to the link
exit();
?>
All I want it to do is if I point a link to www.mysite.com/jump.php?=1 is to redirect in this case to www.yahoo.com. Any thoughts I what I did wrong?
if ($id == "") {$link = "http://www.mysite.com";} //Default Blank
if ($id == "1") {$link = "http://www.yahoo.com";} // COMMENT
if ($id == "2") {$link = "http://www.google.com";} // COMMENT
if ($id == "3") {$link = "http://www.webmasterworld.com";} // COMMENT
Single quotes would work too.
:-)
JK
Hmm, I'd say it's likely that $link is not set somehow when you get to the header("Location: $link") line.
I'd make a few changes, first your links to "www.mysite.com/jump.php?=1" should look more like:
www.mysite.com/jump.php?id=1
Also, your $link = should have quotes of some type around the urls, like so:
$link = 'http://www.mysite.com';
Next, make sure that $id is set to the right thing. Add this line to the beginning of your script:
$id =$_GET['id'];
That should fix your script as it is now. :)
Another solution in this situation would be a switch statment.
$id = $_GET['id'];
switch ($id)
{case 1:
header("Location: [yahoo.com");...]
break;case 2:
header("Location: [google.com");...]
break;case 3:
header("Location: [webmasterworld.com");...]
break;default:
header("Location: [mysite.com");...]
break;}
dc