[Phaos] PHP view source class.
Posted: Thu Mar 09, 2006 3:53 pm
Hey all, i have another quick request.
Could somebody possibley help me finish this class.
Basicly it is a file called source_view.class.php
that allows your to do:
And it will print a pretty source of the php file, with line numbers and everything.
So far i have:
I just need to mod the _checkPathSafe so it only allows files in the directory or beneath the same as sourceview.php
so:
Any tips?
Could somebody possibley help me finish this class.
Basicly it is a file called source_view.class.php
that allows your to do:
Code: Select all
$source = new sourceView("file.php");
$source->viewSource();So far i have:
Code: Select all
class sourceView {
var $_file = "";
function sourceView($file){
$this->_file = $file;
}
function _checkPathSafe(){
// NEED TO HAVE A NICE LITTLE THING TO MAKE SURE THE PATH IS SAFE..
if(file_exists($this->_file)) return true;
return false;
}
function viewSource(){
if(!$this->_file || !$this->_checkPathSafe()) exit;
echo "<table id=\"source_view\"><tr><td width=\"30\"><code>";
for ($i = 1; $i <= count(file($this->_file)); $i++) echo $i.".<br>";
echo "</code></td><td><code>";
highlight_file($this->_file);
echo "</code></td></tr></table>";
}
}so:
Code: Select all
$source->viewSource("../blah.php"); => fails.
$source->viewSource("/usr/..."); => fails.
$source->viewSource("./file.php"); => works.
$source->viewSource("file.php"); => works.
$source->viewSource("folder/subfolder/anotherfolder/file.php"); => works.
$source->viewSource("./folder/subfolder/anotherfolder/file.php"); => works.