View unparsed PHP code
NOTICE: This PHP script was originally written by Scott Hurring. The original code for this script can be found by
clicking here
.
\nreal_path=$real_path
\ndir_name=$dir_name
\n"; // Does the URL requested resolve to a valid path on the server? if (!$real_path) die("File does not exist"); // Is there a directory part to this request? // If $url is a directory, this test will fail. This script can only be used // to view individual files -- if $url is a directory, this script will die. if (!is_dir($dir_name)) die("Non-existant or Invalid directory"); // Compare the requested file's directory against our list of "protected" directories. // If the req'd file is in one of the these directories, this script will die. //print "requested dir = $dir
"; foreach ($protected as $idir) { $invalid_path = realpath($DOC_ROOT . $idir); //print "compared with bad_dir = $invalid_path
"; if ($dir_name == $invalid_path) die("Invalid directory"); } // Now, attempt to resolve where the requested directory is in the document_root $dir_name .= '/'; if (! preg_match("!^{$main->doc_root}!", $dir_name) ) die("Invalid file, not in document root"); // Is the file a real file? if (!is_file($real_path)) die("Invalid file, doesn't exist"); /* If execution gets here, we've established that the reqeusted URL is a valid file in the document_root and NOT in any of the protected directories. So now, a decision is made how to present the requested file. */ if ($type == 'plain') { // Mozilla will understand, MSIE will not. header("Content-type: text/plain\n\n"); /* MSIE has a real problem coping with Content-Type: and certain other directives and instead will usually try and decide (based on file contents and/or name) what to do with a file... so i'll print out a little note letting people know to click on "View Source" to get the actual code, *NOT* to cut-paste directly from the browser! */ if (preg_match('/MSIE/', $GLOBALS['HTTP_USER_AGENT'])) { $MSIE = 1; print "
ALERT!! MSIE won't properly handle the". "\"Content-type: text/plain\" directive.
\n". "Please do NOT copy the following data directly from the browser window,
\n". "because it is not what you want. (MSIE has mangled it).
\n". "To get the source code for this document, you must right click
\n". "this document and select \"View Source\".
\n". "\n\n"; } // Get all the lines in the file and print them directly out readfile($real_path); exit; } // *ADDED BY D.L. } // Create a userinput form so user can enter the url into a // form instead of sending url to script as part of a link else { echo <<
View Unparsed PHP code
Enter a URL (relative to document root) below and press submit.