PHP Include question

Ok Im tryin to load the page say… index.php?page=Contact

and I wanna use <? include ("templates/contact.inc") ?>

But where it says contact.inc i want that to pull from the address i thought it would be something like <?php include ($_GET[$page]); ?> but it doesnt seem to be working. So it would pull what ever page you request. ?page=News it will automaticly include the new.inc file.

Does anyone know?

check the securety of ur script: http://php.net/security.variables

u should call the includes whatever.inc.php (otherwise people might be able to view the source of whatever.inc)

what habbens if i enter something like index.php?page=…/hiddendir/highsensitvefile

try:
[php]<?php
$vailed=(‘contact’,‘news’);

if(in_array($_GET[‘page’],$vailed)) include (‘template/’.$_GET[‘page’].’.inc.php’);
?>[/php]

watch ur spelling (case) ‘contact’ is not the same as ‘Contact’

or u may wanna translate it using an array:
[php]<?php
$page2include=(‘Contact’=>‘template/contact.inc.php’,‘News’=>‘template/new.inc.php’);

if(isset($page2include[$_GET[‘page’]])) include ($page2include($_GET[‘page’]));
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service