首页 ip地址查询 个人资料 用户注册 修改密码 博客 简历 follow me on twitter 本项目主页(参与本项目) 本站源码Svn(仅checkout) 源码查看器 提问的智慧
当前位置: 首页 > 源码查看器
现有8个注册用户
Source of /source.php
  1. <?php
  2. /**
  3.  * 源码查看器
  4.  * @author rains31@gmail.com
  5.  */
  6. define('RAINS_ROOT',dirname(__FILE__));
  7. $page_id 10;
  8. require RAINS_ROOT.'/bootstrap.php';
  9. require INCLUDE_PATH.'/header.php';
  10. $file=isset($_REQUEST['file'])?$_REQUEST['file']:$_SERVER['PHP_SELF'];
  11. ?>
  12. <div id="main">
  13. <fieldset>
  14. <legend> Source of <?php echo $file?> </legend>
  15. <code>
  16. <ol>
  17. <?php
  18. $allowed_dir = array(SITE_PATH.'/',SITE_PATH.'/include',SITE_PATH.'/data');
  19. $allowed_type = array('.php');
  20. $dir strtr(dirname($file), DS'/');
  21. $type strrchr($file,'.');
  22. if(in_array($dir,$allowed_dir) && in_array($type,$allowed_type) && strpos($file,'..')===false && file_exists($_SERVER['DOCUMENT_ROOT'].$file))
  23. {
  24.     $contents file_get_contents($_SERVER['DOCUMENT_ROOT'].$file);
  25.     $contents highlight_string($contents,true);
  26.     $contents str_replace('','',$contents);
  27.     $contents str_replace('','',$contents);
  28.     $contents str_replace('<code>','',$contents);
  29.     $contents str_replace('</code>','',$contents);
  30.     $contents preg_replace('/(require.*?)(INCLUDE_PATH)(.*?\'\/)([^\']*?\.php)(\')/','\\1\\2\\3<a href="source.php?file='.SITE_PATH.'/include/\\4">\\4</a>\\5',$contents);
  31.     $contents preg_replace('/(require.*?)(RAINS_ROOT)(.*?\'\/)([^\']*?\.php)(\')/','\\1\\2\\3<a href="source.php?file='.SITE_PATH.'/\\4">\\4</a>\\5',$contents);
  32.     //$contents = preg_replace('/(require.*?)(.*?\')([^\']*?\.php)(\')/','\\1\\2<a href="source.php?file='.$dir.'/\\3">\\3</a>\\4',$contents);
  33.     echo '<li />'.str_replace('<br />','<li />',$contents);
  34. }
  35. else
  36. {
  37.     echo $file.'是不可查看的文件';
  38. }
  39. ?>
  40. </ol>
  41. </code>
  42. </fieldset>
  43. </div>
  44. <?php
  45. require INCLUDE_PATH.'/footer.php';
  46. ?>