Out links trough a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Out links trough a file

Post 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/");
}
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Post by gangboy »

That would work; but what if the page has another tld (ie: instead of .com would be .ro)?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Post by gangboy »

That was the original ideea and I guess that should do it in the end.

Thanks!
Post Reply