Is Viewing PHP Source Code Possible?

Viewing a website's source code shows only HTML, not PHP Code

Cat 5 cable connecting server equipment
Alexandra Ribeiro/EyeEm/Getty Images

With many websites, you can use your browser or another program to view the document's source code. This is a common occurrence by viewers who want to see how a website developer accomplished a feature on a website. Anyone can view all the HTML that was used to create the page, but even if the web page contains PHP code, you can only view the HTML code and the results of the PHP code, not the code itself.

Why PHP Code Isn't Viewable

All PHP scripts are executed on the server before the website is delivered to the site viewer. By the time the data gets to the reader, all that is left is the HTML code. This is why a person can't go to a .php website page, save the file and expect it to work. They can save the HTML and see the results of PHP scripts, which are embedded inside the HTML after the code is executed, but the script itself is safe from curious eyes.

Here is a test:

The result is PHP Code Test, but the code that generates it isn't viewable. Although you can see that there must be PHP code at work on the page, when you view the document source, you only see "PHP Code Test" because the rest is just instructions for the server and is not passed on to the viewer. In this test scenario, only the text is sent to the user's browser. The end user never sees the code.

mla apa chicago
Your Citation
Bradley, Angela. "Is Viewing PHP Source Code Possible?" ThoughtCo, Aug. 27, 2020, Bradley, Angela. (2020, August 27). Is Viewing PHP Source Code Possible? Retrieved from Bradley, Angela. "Is Viewing PHP Source Code Possible?" ThoughtCo. (accessed January 22, 2021).