<?
//
// This material contains IBM copyrighted sample programming source
// code DB2(R) UDB PHP Demo. IBM grants you a nonexclusive copyright
// license to use the Sample Code as an example from which you can
// generate similar function tailored to your own specific needs.
// Your license to this Sample Code provides you no right or licenses
// to any IBM patents.
//
// The Sample Code is provided by IBM for illustrative purposes
// only. The Sample Code has not been thoroughly tested under
// all conditions. IBM, therefore, does not guarantee or imply
// its reliability, serviceability, or function. IBM provides
// no program services for the Sample Code.
//
// All Sample Code contained herein is provided to you "AS IS" without
// any warranties of any kind. THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
// AND NON-INFRINGMENT ARE EXPRESSLY DISCLAIMED. SOME
// JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
// WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY
// TO YOU. IN NO EVENT WILL IBM BE LIABLE TO ANY PARTY
// FOR ANY DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL
// DAMAGES FOR ANY USE OF THE SAMPLE CODE INCLUDING,
// WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
// INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
// YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE,
// EVEN IF WE ARE EXPRESSLY ADVISED OF THE POSSIBILITY
// OF SUCH DAMAGES.
//
// (C) Copyright IBM CORP. 2001
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
// Licensed Material - Property of IBM
//////////////////////////////////////////////////////////////
// iSeries Linux DB2/PHP/ODBC Demo
// Written by Dave Boutcher (boutcher@us.ibm.com)
//////////////////////////////////////////////////////////////
// This PHP script shows a PHP source file and maps all the
// includes to links
//////////////////////////////////////////////////////////////
// Make sure we get asked for a file name
if (isset($_GET["filename"])) $filename = $_GET["filename"];
else if (isset($_POST["filename"])) $filename = $_POST["filename"];
else $filename = '';
if (!$filename) {
$errmsg = "No file name provided";
include("error.inc");
exit;
}
// Allow file names to have only letters, numbers, periods, and underscores
// This restricts files from being opened in other directories
if (! preg_match("/^[A-Za-z0-9\._]+$/", $filename)) {
$errmsg = "Insecure filename given";
include("error.inc");
exit;
}
// Open the file
$fd = fopen($filename,"r",1);
if (!$fd) {
$errmsg = "Error opening file $filename";
include("error.inc");
exit;
}
// Read the file and close it
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
// Now translate all special characters so they will appear correctly
$trans = get_html_translation_table(HTML_ENTITIES);
$encoded = strtr($contents, $trans);
// This magic line converts include("file") to a link to a file
$encoded = preg_replace("/include\("([a-zA-Z0-9_\.]*)"\)/",
"include(\"<a href=\"showsource.php?filename=$1\">$1</a>\")",
$encoded);
// Output the page header
include("html_tophdr.inc");
echo "<td>";
echo "<h1 align=center>$filename</h1>";
// Output the source
echo "<table><tr><td><pre>$encoded</pre></td></tr></table>";
// Output the page footer
include("html_mainftr.inc");
?>
|