Oliver Bayes-Shelton
Oliver Bayes-Shelton

Reputation: 6292

How can I view PHP source code on a live site?

Is it possible to view the PHP code of a live website ?

Upvotes: 23

Views: 172054

Answers (12)

Abdulfattah
Abdulfattah

Reputation: 138

No, it's not possible as this is considered as security breach

Upvotes: 0

Spooky
Spooky

Reputation: 1316

The only NORMAL way to view PHP source code sitting in some file is to use phps extension, instead of normal php extension. If you make the file extension .phps, decently configured server will output a color-formated source instead of generated html that one would expect. Any other scenario than this one is considered a BIG flaw and the one behind should - panic.

Upvotes: 0

Vipul Jethva
Vipul Jethva

Reputation: 675

You can't do that. Because the server side script (here PHP scripts) execute on the web server and its output is embedded inside HTML which is then thrown back to your browser. So all you can view is the HTML. Just imagine, if what you asked was possible, then evryone would have the source code of facebook, flipkart in their hands now.

Upvotes: 1

evandrix
evandrix

Reputation: 6210

check out php://input and php://filter/convert.base64-encode/resource=<filepath>, eg. http://level11.tasteless.eu/index.php?file=php://filter/convert.base64-encode/resource=config.easy.inc.php

Upvotes: 0

Limitless isa
Limitless isa

Reputation: 3802

Current Page add to php code: http://php.net/manual/en/function.show-source.php

 <?php show_source(__FILE__); ?> 

Upvotes: 4

Wim ten Brink
Wim ten Brink

Reputation: 26682

Everyone is wrong! Yes, it is possible! But if you do see the code in your web browser then this would be a serious security breach or some major trouble in the web server. I've seen it happen once, where some dumb administrator had removed the PHP extension for IIS thus the browser provided all sources as text files instead of executing them.

Then again, there is an alternative method, which is through FTP. Most websites give access to their file system through FTP, so administrators don't need physical access to the system. You will need to know username and password, plus the FTP address to get access, but once you have this information, you have access to the whole site. Useful for administrators, yet also a very good reason to be very careful with passwords.

Upvotes: 9

Paige Ruten
Paige Ruten

Reputation: 176743

There are a few sites that allow you to view their PHP source. Try googling for inurl:viewsource.php (my site should turn up in there somewhere :)).

Also you can view php.net's source: http://www.php.net/source.php?url=/index.php

Upvotes: 0

catfarm
catfarm

Reputation: 363

Usually, no, as others have said, unless of course this is something you want to be the case. Then you can set it up so that using .phps (or any other extension really, but this is the norm) will display the source code of the page (with syntax coloring I believe). Something like:

AddHandler application/x-httpd-php-source .phps

in your apache configuration should do the trick.

Note, you will need to save your .php files with a .phps for their source to be displayed.

Upvotes: 9

lpfavreau
lpfavreau

Reputation: 13211

Not if PHP is configured properly.

PHP is served already interpreted to the visitor.

Seeing the PHP code on a live website would be considered hacking which is probably outside the ethical scope of stackoverflow.

Upvotes: 2

Benjamin Wohlwend
Benjamin Wohlwend

Reputation: 31858

No, unless the server admin screwed up.

Upvotes: 2

David McEwing
David McEwing

Reputation: 3340

Do you have access to the files on the live server? If so yes, otherwise no, it is only possible to see the result of the script execution.

Upvotes: 2

Jonathan Prior
Jonathan Prior

Reputation: 6284

No, as it is interpreted on the server-side and the results are sent to the user. If you want to view the source code of a site you control in-browser, consider the FirePHP extension for Firebug, or just access your site files with your preferred method.

Upvotes: 29

Related Questions