Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created September 25, 2010 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/596937 to your computer and use it in GitHub Desktop.
Save walterdavis/596937 to your computer and use it in GitHub Desktop.
A quickie source view for files, using the PHP stream wrappers for file_get_contents()
<?php
$out = '';
if(isset($_GET['src']) && !empty($_GET['src']) && strstr($_GET['src'],'..') === false){
if(file_exists('./' . $_GET['src'])){
$out = file_get_contents('./' . $_GET['src']);
}else{
$out = 'error traversing filesystem';
}
}elseif(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $_SERVER['REQUEST_URI']){
$out = file_get_contents($_SERVER['HTTP_REFERER']);
}
$out = highlight_string($out, true);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Source View</title>
<style type="text/css" media="screen">
html, body {
padding: 0;
margin: 0;
width: 100%;
min-height: 100%;
}
body {
background-color: #ccc;
}
pre {
width: 750px;
margin: 24px auto;
padding: 8px 20px;
overflow-x: auto;
border: 12px solid #666;
background-color: #efefef;
}
#back {
width: 804px;
margin: 24px auto;
text-align: right;
}
</style>
</head>
<body>
<div id="back"><a href="javascript:history.go(-1);">back</a></div>
<pre><?=$out?></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment