| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #2 (permalink) |
| Senior Member | 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 |
| |
| | #5 (permalink) |
| Senior Member | 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: Last edited by localhost; 08-12-2007 at 04:55 AM. |
| |
| | #6 (permalink) | |
| fka: 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. Quote:
| |
| |
| | #7 (permalink) | |
| Senior Member | Quote:
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. | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |