|
Posted by Rauch Christian on 10/01/05 19:40
Joe schrieb:
>>>Joe said the following on 01/10/2005 15:02:
>>>
>>>>Does anyone know if a show source button exists written in php? I want
>>>>to
>>>>add this button to a web page so by a click of a button the source code
>>>>of
>>>>that page is displayed.
>>>>I found several but they use javascript which I want to stay away from
>>>>because I don't want the button code itself to appear when viewing the
>>>>source.
>>>>
>>>
>>>Do you mean the HTML source, or the PHP source?
>>>
>>>For HTML, the user can just click on View->Page Source (or the
>>>equivalent).
>>>
>>>For PHP source, if you save a file with a .phps extension, you can
>>>configure your server to get PHP to highlight these files on request,
>>>e.g. with Apache, add the following line to config file:
>>>
>>>AddType application/x-httpd-php-source .phps
>>
>>Also:
>>http://us2.php.net/manual/en/function.highlight-file.php
>
>
> My bad... Sorry.
> I want to view the html code, not the php. I know you can do it through the
> browser but I need it for a 'convenience' situation (long story). Any
> ideas??
>
>
You could try a seperate page opened either through a link or a
javascript popup, which reads via fopen (if allowed) the page over http.
Try the code below, but it is without any error checking! You still have
to check, if the site given is valid and if it is a site you want them
to see!
-rauch
<?php
if(isset($_GET['site'])){
$out = "GET ".$_GET['site']." HTTP/1.1\r\n";
$out .= "Host: ".$server."\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
if($fp!=false){
//Echo some header
while (!feof($fp)) {
$output. = htmlentities(fgets($fp, 128));
}
//Do some Highlighting (don't know if the function above
//is capable of html highlighting
//Echo some footer
} else {
//Output error message
}
fclose($fp);
} else {
//Error Message
}
?>
[Back to original message]
|