[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 08-11-2007, 06:55 PM   #1 (permalink)
New Member
 
Join Date: May 2007
Posts: 12
0.00 NP$ (Donate)

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, 08:22 PM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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.

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, 04:45 AM   #3 (permalink)
New Member
 
Join Date: May 2007
Posts: 12
0.00 NP$ (Donate)

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, 04:49 AM   #4 (permalink)
mvl
fka: leonardo
 
Join Date: Aug 2006
Posts: 720
30.00 NP$ (Donate)

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, 04:50 AM   #5 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

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 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
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 04:55 AM.
Xyzer is offline  
Old 08-12-2007, 05:08 AM   #6 (permalink)
mvl
fka: leonardo
 
Join Date: Aug 2006
Posts: 720
30.00 NP$ (Donate)

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.

Quote:
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);
} 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, 05:15 AM   #7 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

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 all

Tsunami Relief AIDS/HIV
Quote:
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 05:18 AM.
Xyzer is offline  
Old 08-12-2007, 05:44 AM   #8 (permalink)
New Member
 
Join Date: May 2007
Posts: 12
0.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 06:06 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85