how to make those easy links (like: blah.php?id=01)

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
snake
Forum Newbie
Posts: 5
Joined: Tue Oct 01, 2002 1:27 pm

how to make those easy links (like: blah.php?id=01)

Post by snake »

well the topic tells it all, how to make those easy links like blah.php?id=01
instaed of /fsdf/fdsf/fds/bleh.php

thanks
bumpy
Forum Newbie
Posts: 2
Joined: Wed Nov 20, 2002 7:29 am
Location: Furtwangen/Germany
Contact:

Post by bumpy »

well, if you just have a few pages with your website you could use a switch:

You build your index.php for example like this:

Code: Select all

<?php
include("header.php");
//here your Menu with links like <a href="?id=1">page1</a>

switch ($_GETї"id"]) {
         case 1:       include("1.php");        break;
         case 2:       include("2.php");        break;
         case 3:       include("3.php");        break;
         default:       include("4.php");
         }
include("footer.php");
?>
in 1.php, 2.php, ... you put your content; in the header.php and footer.php you put your html-layout

Wasn't that hard, huh?! :wink:
snake
Forum Newbie
Posts: 5
Joined: Tue Oct 01, 2002 1:27 pm

Post by snake »

isn't there any other way to do this aswell if i want to link to a whole new page instead of using include...

i mean like if i want to link to eg php.net

i mean that ?id=php poits to php.net or similiar
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you wanted to then send people to another page entirely you would have to use header() to redirect them. So it's almost the same as bumpy's example, however, you wouldn't want any output whatsoever before the header() function call (viewtopic.php?t=1157)

Code: Select all

<?php

$id = (!empty($_GETї'id']) ? $_GETї'id'] : '';

switch ($id) { 
	case 'php':
		header('Location: http://www.php.net/');
		break; 
	case 'mysql':
		header('Location: http://www.mysql.com/');
		break; 
	default:
		header('Location: http://www.mysite.com/');
} 
?>
Mac
Post Reply