View previous topic :: View next topic |
Author |
Message |
Guest
|
Posted: Sat Oct 26, 2002 2:18 pm Post subject: showing source |
|
|
Hello,
I'm using highlight_file() to show the sourcecode og my scripts, but it doesn't work as I want it to.
Whenever I try to show the source of a .php file, it outputs all the HTML code as well and does not format it properly.
I've set up the server to parse .html as PHP as well, and when I show the source of those files, it works like a charm :)
Any ideas?
I'm using PHP 4.3.0-snaps of a few days back with 1.1RC1.
kekePower |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sat Oct 26, 2002 11:31 pm Post subject: Re: showing source |
|
|
Anonymous wrote: | Hello,
I'm using highlight_file() to show the sourcecode og my scripts, but it doesn't work as I want it to.
Whenever I try to show the source of a .php file, it outputs all the HTML code as well and does not format it properly.
I've set up the server to parse .html as PHP as well, and when I show the source of those files, it works like a charm :)
Any ideas?
I'm using PHP 4.3.0-snaps of a few days back with 1.1RC1.
kekePower |
Can you tell us more about how you do things ? What is the script you use for example ? How .php output is ? Any examples would help figuring out the problem. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
Guest
|
Posted: Sun Oct 27, 2002 12:14 pm Post subject: Re: showing source |
|
|
aprelium wrote: | Can you tell us more about how you do things ? What is the script you use for example ? How .php output is ? Any examples would help figuring out the problem. |
Hi,
I'm using, as mentioned, http://www.php.net/highlight_file to show the sourcecode.
The example looks like:
Code: |
<?php
$script = $_SERVER["PATH_TRANSLATED"];
if(!$script) {
echo "<BR><B>ERROR: Script Name needed</B><BR>";
} else {
if (ereg("(\.php|\.inc|\.html)$",$script)) {
print "<H1>Source of: $_ENV[PATH_INFO]</H1>\n<HR>\n";
highlight_file($script);
} else {
echo "<H1>ERROR: Only PHP or include script names are allowed</H1>";
}
}
echo "<HR>Processed: ".date("Y/M/d H:i:s",time());
?>
|
My code is slightly changed because I'm using 4.3.0-dev...
And the URL would then look something like: http://server.com/source.php/file.php
But it only displays the HTML output of the last file...
It _may_ be a bug in PHP, because all the variables shows up in phpinfo().
Oh, BTW, I'm using Win2k Pro.
Thanks.
kekePower |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sun Oct 27, 2002 8:27 pm Post subject: Re: showing source |
|
|
PHP used as a CGI interpretr seems to run automatically any script put as a path info (this is to support the way Apache runs scripts :-( ).
That's the explanation of the behavior you experienced (it isn't only in version 4.3.0,
we tested older versions and they all do the same).
But the good news is that there is a workaround.
You will need to create SHTML file which will call your source.php.
Create a file in htdocs/ called source.shtml with the following content:
Code: | <!--#exec cgi="/source.php" --> |
Then modify your source.php in order to use the redirected PATH_INFO and
PATH_TRANSLATED variables.
Code: | <?php
$script = $_ENV["REDIRECT_PATH_TRANSLATED"];
if(!$script) {
echo "<BR><B>ERROR: Script Name needed</B><BR>";
} else {
if (ereg("(\.php|\.inc|\.html)$",$script)) {
print "<H1>Source of: $_ENV[REDIRECT_PATH_INFO]</H1>\n<HR>\n";
highlight_file($script);
} else {
echo "<H1>ERROR: Only PHP or include script names are allowed</H1>";
}
}
echo "<HR>Processed: ".date("Y/M/d H:i:s",time());
?> |
REDIRECT_PATH_TRANSLATED and REDIRECT_PATH_INFO contain the value of PATH_TRANSLATED
and PATH_INFO that were passed to source.shtml.
Check that SSI processing is enabled and that shtml is declared as an SSI associated extension.
That's it. All you have to do now is to use http://server.com/source.shtml/file.php. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|