I am looking for some advice on how to do something within PHP, i know it is possible and have seen examples before, however I am not sure how to implement this myself.

What i am looking at doing is including PHP pages within a main PHP page.
for instance i have index.php and i want to include contacts.php inside the index page.
the url looks something like this: http://www.mysite.com/index/php?t=contacts

My questions is what is this called? and where can i learn about doing it effectively.

I have used Include() and Include_Once() before and this is not the same thing.

Any one have any ideas for me?

Thank you for your time!

You can do this like this :


$file = $_GET['t'].".php";
include ($file);


This will include contacts.php in your index.php :cool:

commented: Thanks for the ideas man! +1

Awesome Thanks. This is close to what i did any way.

I used links like:

<a href="index.php?p=contacts">Contacts</a>

then i have a Switch Case:

switch ($_GET[p]) {
require: "contacts.php";

Thanks for the help!

For all those noobs out there like me:

In the URL when there is a ? after the page name as in my index.php?p=contacts
the PHP will read the following Information as a $_GET.
thus when i $_GET[p] the page reads the following from after ? and will interpret it from there..
If any one can make this any clearer please help!

Hi joshua.tilson,

It appears that this can be streamlined even more, however, you will have to put some safegaurds in to make sure there is no fowl play (which should be done anyway). This is what it could be:


require((preg_match('/(contacts|about|home)/i',$_GET['p'])) ? $_GET['p'] : 'fowlplay.php');