1. Computing & Technology

Discuss in my forum

Your PHP code can't be viewed by viewing the document source

By , About.com Guide

With some websites, you can use your browser (or another program) to view the document's source code. You can view all of the HTML that was used to create the page. If you were to inspect a PHP page, you could only see the HTML it outputs, you would not see any of the PHP coding. All of your PHP scripts are executed on the server before they are delivered to the site viewer. By the time the data gets to the reader, all that is left is the HTML code. This is also why a person can't go to your .php website page, save the file, and expect it to work. They are only saving the HTML that the script outputted, the script itself is safe.

Here is an example:

<?php
Echo "PHP Code Test";
?>

Although you can see that there is in fact PHP code generating the page, if you view the document source you will only see "PHP Code Test" because the rest is just instructions for the server and is not passed on to the reader. In our test scenario, only the text is sent to the user's browser. They end user never sees the code.

©2012 About.com. All rights reserved.

A part of The New York Times Company.