Page 1 of 1

Out links trough a file

Posted: Thu Jan 08, 2004 10:10 am
by gangboy
If for example I call link.php like this:

http://localhost/link.php?page=yahoo

how should link.php look?

This is an ideea of mine but my PHP knowledge is very limited:

Code: Select all

<?php
if (!empty($_GET['page'])) { 
    $page = $_GET['page'];
} else { 
    $page = "$null";
}

if ($page == "yahoo") {
	header("Location:http://www.yahoo.com/");
}
?>

Posted: Thu Jan 08, 2004 10:18 am
by JayBird
what you had was okay, but you would have to hard code loads of header locations.

what about this

Code: Select all

<?php 
if (!empty($_GET['page'])) { 
    $page = $_GET['page']; 
} else { 
    $page = "null"; 
} 

if ($page != "null") { 
   header("Location:http://www.$page.com/"); 
}  else {
   echo "no link selected";
}
?>
Mark

Posted: Thu Jan 08, 2004 10:20 am
by gangboy
That would work; but what if the page has another tld (ie: instead of .com would be .ro)?

Posted: Thu Jan 08, 2004 10:21 am
by JayBird
yup, that would be a problem

why not have your link like

http://localhost/link.php?page=www.yahoo.com

then

Code: Select all

<?php 
if (!empty($_GET['page'])) { 
    $page = $_GET['page']; 
} else { 
    $page = "null"; 
} 

if ($page != "null") { 
   header("Location:http://$page"); 
}  else { 
   echo "no link selected"; 
} 
?>
Mark

Posted: Thu Jan 08, 2004 10:23 am
by gangboy
That was the original ideea and I guess that should do it in the end.

Thanks!