FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


include() Problem





polly-gone
I am kinda sorta new to PHP and I am trying to make dynamically loading pages. For example the home page like is:

Code:
<a href="index.php?nav=main&?page=home">


I can get the ?nav (Navigation bar) to load by using

Code:
<?php include($nav); ?>


What could the problem possibly be? I have a called main.php that is supposed to go there.

-Nick Smile

Edit: Whoops.... said index.html instead of index.php..
mathiaus
You need to use $_GET['nav']
polly-gone
oh okay. Do I have to use include() at all?
mathiaus
If you need to include a file. Just replace the $nav with $_GET['nav']

In fact, replace it with this, it's more secure
Code:
$start = '/home/username/domains/yourdomain/public_html/';
$nav = $_GET['nav'];
if(file_exists($start.$nav.'.php')){
   include($start.$nav.'.php');
}
else {
   header('Location: http://yourdomain/403.shtml');
}
Manofgames
Code:

$start = '/home/username/domains/yourdomain/public_html/';
$nav = str_replace(array('\\','/'), '', $_GET['nav']);;
if(file_exists($start.$nav.'.php')){
   include($start.$nav.'.php');
}
else {
   header('Location: http://yourdomain/403.shtml');
}


A little more security for you Wink
lukand
mathiaus wrote:
You need to use $_GET['nav']


I think $_POST
DanielXP
lukand wrote:
mathiaus wrote:
You need to use $_GET['nav']


I think $_POST


POST gets it if someone POSTS a form. GET, GETs it from the URL
manav
u need to fetch the get value first

do this

$nav = $_GET['nav'];

or

$nav = $_REQUEST['nav'];

then do what ever you r doin and it shall work Very Happy Smile Very Happy
JayBee
Just remember. If you use variable $nav without any testing of its validity, it is nice backdore to your system.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.