NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP dynamic includes

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-11-2007, 07:55 PM THREAD STARTER               #1 (permalink)
New Member
Join Date: May 2007
Posts: 12
vicken is an unknown quantity at this point
 



PHP dynamic includes


Quick question, How do Dynamic includes work, and more importantly how does linking work with dynamic includes. thanks in advance
Ian.
vicken is offline  
Old 08-11-2007, 09:22 PM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
what exactly do you mean, dynamically include what, also in what ways are they dynamic.
????: NamePros.com http://www.namepros.com/programming/360699-php-dynamic-includes.html

A normal includes can be done in either of 4 ways:-

include('./path/to/document.php')
include_once('./path/to/document.php')
require('./path/to/document.php')
require_once('./path/to/document.php')

These all include the content of the php script (or whatever type of script it is and treats the content as if it were in the current document. The difference between the requore and includes functions is that a script that has an included file that cannot be found will throw a warning but continue. If you had used a require function then it will throw a warning plus a fatal warning (which will terminate the script). The function with once in the name simply stop you including/requiring a script already included (script will ignore and continue as usual.

You can use variables within the file names such as:-

$var = 'file.php'
require_once('./path/to/'.$var);

And of course that variable can come from anywhere a variable can normally come from. HOWEVER if you use a variable that the user has supplied then you should sanitize it 100%. I found a bug in a forum a few months ago that enabled you to include any file on the server because they were using this type of thing. They did not bother checking the file name and did not ensure it was within an allowed path.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 08-12-2007, 05:45 AM THREAD STARTER               #3 (permalink)
New Member
Join Date: May 2007
Posts: 12
vicken is an unknown quantity at this point
 



What im trying to find out is. A guy i was talking to said he made a site that really made up of smaller content pages dynamicly included into the main page.
vicken is offline  
Old 08-12-2007, 05:49 AM   #4 (permalink)
mvl
fka: leonardo
Join Date: Aug 2006
Posts: 736
mvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of light
 



I think he was referring to using 'include(_once)' or 'require(_once)' within conditional statements like 'if .. then .. else' or 'switch' statements.
__________________
ForeignPropertyForSale.com
SATAN.EU VOI.EU
mvl is offline  
Old 08-12-2007, 05:50 AM   #5 (permalink)
Senior Member
 
Xyzer's Avatar
Join Date: Aug 2005
Location: United Kindom
Posts: 1,502
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
 


Tsunami Relief AIDS/HIV
Ahh hello, Just saw your post, I think I know what you mean.
To access links like www.blah.com/index.php?page=about then it will include about.php. You will want to do something like in the post below:

PHP Code:
<?php
// index.php
????: NamePros.com http://www.namepros.com/showthread.php?t=360699
if(isset($_GET['page']) && strlen($_GET['page'] < 100)) {
$fileName html_entities($_GET['page']);
$ext '.php';
$file $fileName.$ext;
if(
is_file($file)) {
include(
$file);
} else {
echo 
'Page name incorrect.';
}
} else {
echo 
'Page not set.';
die();
}
?>
There may be errors inthat.. it's off the top of my head so may be slightly incorretct.
Last edited by localhost; 08-12-2007 at 05:55 AM.
Xyzer is offline  
Old 08-12-2007, 06:08 AM   #6 (permalink)
mvl
fka: leonardo
Join Date: Aug 2006
Posts: 736
mvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of lightmvl is a glorious beacon of light
 



A little warning: the code below is unsafe. You should NEVER let the name of the file to be included (=executed) be specified in request vars without any checks.

Originally Posted by localhost
Ahh hello, Just saw your post, I think I know what you mean.
To access links like www.blah.com/index.php?page=about then it will include about.php. You will want to do something like in the post below:

PHP Code:
<?php
// index.php
if(isset($_GET['page']) && strlen($_GET['page'] < 100)) {
$fileName html_entities($_GET['page']);
$ext '.php';
$file $fileName.$ext;
if(
is_file($file)) {
include(
$file);
????: NamePros.com http://www.namepros.com/showthread.php?t=360699
} else {
echo 
'Page name incorrect.';
}
} else {
echo 
'Page not set.';
die();
}
?>
There may be errors inthat.. it's off the top of my head so may be slightly incorretct.
__________________
ForeignPropertyForSale.com
SATAN.EU VOI.EU
mvl is offline  
Old 08-12-2007, 06:15 AM   #7 (permalink)
Senior Member
 
Xyzer's Avatar
Join Date: Aug 2005
Location: United Kindom
Posts: 1,502
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
 


Tsunami Relief AIDS/HIV
Originally Posted by leonardo
A little warning: the code below is unsafe. You should NEVER let the name of the file to be included (=executed) be specified in request vars without any checks.
You are completely wrong.

First, It cleans the name up and takes out any < > etc. and secondly it checks if the file actually exists. This is as good as you will get it, and if the file doesn't exist, it simply won't run.



Edit: Sorry, you are correct. As Hitch told me just now, you shouldn't let the user include a file like that becuase if you want to keep a file private or something the user could include it.. Sorry.. You win
Last edited by localhost; 08-12-2007 at 06:18 AM.
Xyzer is offline  
Old 08-12-2007, 06:44 AM THREAD STARTER               #8 (permalink)
New Member
Join Date: May 2007
Posts: 12
vicken is an unknown quantity at this point
 



ok this is really confusing....
vicken is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:57 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger