...

View Full Version : Differen includes



NVDW
07-10-2005, 12:28 AM
Hi,

I have a list of links on the left.
Next to it i want to load the page that is together with the link (with include).

Example:

I click on the first link then the file (include1.php) should show up in the table next to the list of links.
Then i click on the second link and the file (include2.php) should show up in the table next to the list of links.

I know how to include a file.
For the first link it = <td><?php include("include1.php") ?></td>
For the second one = <td><?php include("include2.php") ?></td>

But how can i include different files in that same table when i click on a specific link on the left (i don't want to use frame).

I hope anyone can help me out with this. Thank you.

delinear
07-10-2005, 12:38 AM
You can pass a variable to the url from the link which PHP can use to determine which file to include. For instance:

// This is your menu
<a href="page.php?id=home">Homepage</a>
<a href="page.php?id=products">Products</a>
<a href="page.php?id=contact">Contact</a>

<?php
// now let's decide what page to include - the default is "home"
$_GET['id'] = (isset($_GET['id']) ? $_GET['id'] : 'home');

// next we create an array of allowed pages for security purposes only these pages will be loaded as included files
$allowed_pages = array("home", "products", "contact");

if(!in_array($_GET['id'], $allowed_pages)) {

echo 'Sorry, the page you selected could not be found. It may have been moved or deleted.';

} else {

include($_GET['id'] . '.php');

}
This has some added security as it will only include pages you specifically add to the $allowed_pages array.

BaDgEr
07-10-2005, 01:38 AM
This has some added security as it will only include pages you specifically add to the $allowed_pages array.

Wow that's a much better way than I do it.. learn something new every day eh :)

NVDW
07-10-2005, 02:38 AM
Thank you very much!

I still have one question. I already included it before so now i have this is a piece of the php file i include:

<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td width="10" height="20">&nbsp;</td>
<td width="25" height="20"><div align="center"><img src="images/asp.gif" name="1" width="17" height="16" border="0"></a></div></td>
<td width="155" height="20" class="style"><a href="index.php?id=asp">Asp</a></td>
<td width="10" height="20">&nbsp;</td>
</tr>
<tr>
<td width="10" height="20" background="images/content_left_gray.gif">&nbsp;</td>
<td width="25" height="20" bgcolor="#F0F0F0"><div align="center"><img src="images/c.gif" name="2" width="16" height="16" border="0"></a></div></td>
<td width="155" height="20" bgcolor="#F0F0F0" class="style"><a href="index.php?id=c">C</a></td>
<td width="10" height="20" background="images/content_right_gray.gif">&nbsp;</td>
</tr>
Like you said with the id i did it with asp and c. and the link goes to the index page. I hope i did that right...

I have also inserted the php code in the table in the index.php where the different includes should show up and i made an asp.php page but it doesn't work, it gives me the error message that the page could load or doesn't exist :o

NVDW
07-10-2005, 02:40 AM
oh srry it works fine now :) Thank you very much for helping me with this



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum