Google-chrome – Why doesn’t Google Chrome show PHP in page source

browsergoogle-chromePHPsource code

Why doesn't Google Chrome show the PHP in the source?

For example, here's a page I did (mostly with JQuery). I decided to have a small bit of PHP to fetch the IP address and display it (in a beautified way) so that I could login remotely (because my IP changes because of DHCP).

So I wrote it; here's a couple of screenshots.

The source code in my editor:

Imgur

The source code in the browsers viewsource:

Imgur

Just to clarify, I blacked out the IP, but the IP is all it showed on the screen — not the PHP that echoed the variable.

Why does it not show the actual PHP, and is there any way to view the PHP?

Another example is the site I curled to get the ip, icanhazip.com. If you visit the page, it shows your ip; but if you view source in the browser, the page contains only the text of your ip, and none of the code that makes it happen.

How can I view the PHP source?

Thanks!

evamvid

Best Answer

PHP is a server side language and interpreted on the server. After the code is interpreted, only the HTML is transmitted by the webserver to the client (e.g. Chrome).

So, Chrome has no idea the page is even using PHP - all it got from the webserver was HTML, and thus that's all it can show you for source.

Contrast this to a client-side language like javascript, where you can see the raw javascript code . . .

There's no way to see the raw PHP unless the web server is misconfigured and doesn't render PHP, or you access the file directly on the web server, e.g. using FTP, a shell session, etc, instead of via a browser and the web server (e.g. Apache).

Related Question