View Full Version : Any idea how can do this below with "?pathid="
westmatrix99
10-15-2007, 10:09 AM
Any idea how can do this below with "?pathid="
index.php?pathid=link1.php
<a href="index.php">Home</a>
<a href="index.php?pathid=link1.php">Contacts</a>
<a href="index.php?pathid=link2.php">Search</a>
<a href="index.php?pathid=link3.php">Site map</a>
<a href="index.php?pathid=link4.php">Disclaimer</a>
abduraooft
10-15-2007, 10:25 AM
Sorry, your intention is not clear from your question.
Any value passed through url as above will be obtained through $_GET[] globla array. So in you case it'll be $_GET['pathid']
westmatrix99
10-15-2007, 10:31 AM
The objective is to keep the index.php page and just call up the next new page using the include option; hence the link
?pathid=link1.php
I could use iframes but would prefer to use something better than that.
Fumigator
10-15-2007, 04:12 PM
Either we are missing something or this is just a matter of using the $_GET value that is sent, i.e. include ($_GET['pathid']);. Be careful though; you want to verify and validate the values in the $_GET array otherwise those ha><orz will be able to stick anything in your pathid variable which could be bad.
westmatrix99
10-15-2007, 04:20 PM
Got this in the centre of the HTML page.
<?
if(isset($_GET['pathid']))
include('/path/to/files/'.$_GET['pathid']);
else
include('home.php');
?>
I use this to call it:
href="index.php?pathid=page_name.php"
It works, don't need to check it for other stuff - if the page does not exist in the path then it wont show - simple.
Thank you all for your help on this one.
I am converting all my sites that have tables to css as well.
Inigoesdr
10-15-2007, 05:29 PM
Now suppose I pass config.php, or the path to another file on a shared server that would display the contents of your files. Or a file in /tmp. It's not smart at all to just blindly include files based on user input. You need to have a list of files that are allowed to be included. An easy way to do this is make an array, and use in_array() to make sure the file is allowed. If it's not give an error/show the index.
westmatrix99
10-15-2007, 05:52 PM
Sounds great and very helpful;
Only thing is I got this today.
I have no idea how the array system works, or how I would get it work with what I learnt today.
Inigoesdr
10-15-2007, 05:55 PM
$allowed = array('page.php',
'page2.php',
'contact.php',
'main.php'
);
if(in_array($_GET['pathid'], $allowed))
{
include($_GET['pathid']);
}
else
{
// error
}
westmatrix99
10-15-2007, 06:09 PM
This looks good, THANK YOU!
I am testing it right now.
Cheers
West
westmatrix99
10-15-2007, 06:19 PM
Works F'n GREAT - you know your stuff about this PHP and naughty tricks.
Very cool!
THANKS AGAIN
This is what I got:
<?php
$allowed = array('index.php',
'links.php',
'contact.php',
'home.php'
);
if(in_array($_GET['pathid'], $allowed))
{
if(isset($_GET['pathid']))
include('./'.$_GET['pathid']);
//include($_GET['pathid']);
}else{
// error do nothing except tell them off in a nice way.
echo "<BR>";
echo "<BR>";
echo "PISS OFF!";
}
?>
Fumigator
10-15-2007, 06:47 PM
// error do nothing except tell them off in a nice way.
echo "<BR>";
echo "<BR>";
echo "PISS OFF!";
Oh I am SO stealing this code! :D
westmatrix99
10-15-2007, 06:53 PM
Enjoy, it's as free as PHP will ever be.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.