Can you view PHP source?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ben C
Forum Newbie
Posts: 7
Joined: Sat Mar 29, 2003 5:16 am

Can you view PHP source?

Post by Ben C »

Is it possible for someone to download a PHP page without it being executed, so they can see the source?


Cheers
-Ben :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Not if the file has an extension that the webserver recognises as one that needs to be parsed by the PHP engine. For example most webservers are setup with .php as the extension for PHP files, if someone attempts to download one of these files they'll get the output of the PHP script. However, if the same code is placed in a file with a .inc file extension then it might be possible for someone to download the PHP page without it being executed (only not possible if the webserver is setup to view .inc's as PHP files).

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

They aren't nessesarily that big of a security problem. :wink:

click to see what i mean.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Oromian wrote:They aren't nessesarily that big of a security problem. :wink:
Of course the question may not be about security :wink: it may be that he wants to make PHP source available for download :roll: (that's why I purposely didn't phrase my answer as though I was answering a question about security and tried to just give a general response to the actual question asked).

Mac
Last edited by twigletmac on Wed Apr 16, 2003 5:58 am, edited 1 time in total.
Frostbite
Forum Newbie
Posts: 4
Joined: Wed Apr 16, 2003 5:22 am

Post by Frostbite »

you could just put it in a .txt file using notepad and link to it, it will either show the script or you might have to download it first
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

heh ;)

If you don't want anyone to see it, place your source only in .php files, if you do want to show your source, try a snipplet like this one:

Code: Select all

<?php
function highlightcode($file){
ob_start();
show_source( "$file" );
$t = ob_get_contents();
ob_end_clean();
$t = ereg_replace( "<font" , "<span" , $t);
$t = ereg_replace( "</font>", "</span>", $t );
$t = ereg_replace( "color="", "style="color:", $t);
echo $t;
}

/* this has tough security so only the file, index.php inside this directory can be viewed;

./index.php

anything else will leave the visitor with a big fat error message.  */

if($file == "./index.php") {
highlightcode ($file);
} elseif(!$file) {
exit;
} else {
echo "<h1><b>Cannot view this page! <u><font color="red">Access forbidden</font></u>!</b></h1>";
exit;
}
?>
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

I don't think this guy wants to show his source code, I think he wants to view OTHER people's source code.

:P

If you're looking for ideas for code, padawan, go to no place other than hotscripts.com!
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Of course, if the file is in their own possession, simply copy/rename to FILENAME.phps
Image Image
The One
Forum Newbie
Posts: 8
Joined: Sun Apr 20, 2003 4:18 am

Post by The One »

Frostbite wrote:you could just put it in a .txt file using notepad and link to it, it will either show the script or you might have to download it first
or you could just use the addslashes() and encode_url() functions.
Post Reply