Php & Web Tutorials
Online Tools
Code Library
Documents & Guides
Browse Site Source
Forums
Image Gallery
Stuff() 
About
News Archive
FAQ
Contact
Dark2k1() 
LOLosters : Create Posters
ObeseBeasts.com
ExistenceDefined
PowerPortal CMS
DinerStop Reviews
ScenicShare Imagery
ActivTec Web Solutions
Products() 
Dynamic Inclusions - by dark2k1(dark2k1.com)

I. Dynamic Inclusions

Lets say that we had 200 content pages on our site. Now lets say we wanted to add a navigation link. We could go through every file and change it but that takes a lot of time and is very tedious. This is where dynamic inclusions come into play. They allow us to store our the page content in a separate file then have the content file be included in the content area of the layout.

II. The Concept

To help us better understand how dynamic inclusions work we are going to look at some example code.

<?php
echo "The sites header html code";
include($file);
echo "The sites footer html code";
?>

This is a basic example of how a dynamic inclusion works. The layout header html code is displayed. Then the file containing the content is included. Finally the footer html code is displayed. Now that you have a better understanding of dynamic inclusions we can move on to an improved version of the code.

III. The Code

The code we used above has some problems. It can be easily exploited allowing a user to execute malicious code on the server by providing the url of the malicious code on a remote server(ex: http://yoursite.com/index.php?file=http://theirsite.com/badcode.txt). The way we can correct this problem is by specifying a base directory for the include and making sure there are no occurrences of "http://" in the url. Now lets take a look at the code.

<?php
if(stristr($file, "http:////") || stristr($file, "https:////") || stristr($file, "ftp:////")) {
die("Invalid filename");
}

echo "header html code";

include(dirname(__FILIE__) . 'pages/');
/* It will look look for the file in the /pages/ directory */

echo "footer html code";
?>

Now save the code as index.php and place it in the root directory of your site. Now access the script by going to http://yoursite.com/index.php?file=contentpage.html. The script will look for the file in the /pages/ directory.

Posted by QauuvYvXuNefHFaMsWa (Unregistered) on Tuesday, November 4th @ 7:32am EST
1Hz2aS
Name


07 07 07 Montauk : Dsc01990
Hits (4) Comments (0)
 Random Image()
7 user(s) active browsing the site.
7 Guest(s), 0 Member(s)
38.103.63.x, 66.249.67.x, 193.252.149.x, 81.52.143.x, 193.252.149.x, 208.36.144.x, 81.52.143.x
 Who Is Online()
 Quick Search()
 0.69710sec. 15 queries.
fueled by powerportal 2 framework (2.0.13)