note 14052 deleted from function.show-source by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 02:32:47 +0000 |
| Subject: | note 14052 deleted from function.show-source by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21840@lists.php.net to get a copy of this message | ||
If you don't have a program with a line counter, you can use this code snippet to number the
lines of a file's source. It doesn't color the code like show_source(), but it works
nicely for debugging or display purposes. Make sure to specify your desired url ($url)
$file = fopen($url, "r");
$data = fread($file, filesize($url));
fclose($file);
$data = eregi_replace("<", "<", $data);
$data = eregi_replace(">", ">", $data);
$data = trim($data);
$data = split("\n", $data);
$result = "<pre>";
$i = 0;
$line = 1;
while($split = each($data)){
if(strlen($line) == 1){
$third = " ";
}else{
$third = "";
}
$result .= "$line $third$data[$i]\n";
$line++;
$i++;
}
$result .= "</pre>";
echo $result;
If you have an open source web site but want to limit what pages users can see, you can only allow
certain urls with this:
$allowed = array("a.php", "b.php", "c.php");
$pass = "no";
for($i=0; $i<count($allowed); $i++){
if($url == $allowed[$i]){
$pass = "yes";
break;
}
}
if($pass == "yes"){
show_source($url);
}else{
echo "Access denied";
}
Hope that helps somebody!
-Paradox