1. Computing

Discuss in my forum

Why Don't I See My Code When I View Source?

Why saving a PHP page from a browser doesn't work.

By , About.com Guide

If you've ever tried to view the source of a PHP file from your web browser, you may have been surprised to see no PHP code. This is because all the PHP is executed on the server before it is sent to your browser. All your browser ever receives is the results of the PHP. For this same reason, you cannot go to a .php file on the web, save it, and expect to see how it works. You are only saving the page produced by the PHP, and not the PHP itself.

Here is an example:

 <?php
 Echo "My PHP Page";
 ?> 
We can see that the PHP code is echoing the line My PHP Page, however, it is the server that reads this code and then knows to send My PHP Page to your browser. Since the rest of the code is just instructions for the server, it dosen't send anything else. So a view source or a save will simply be the text My PHP Page, that was sent to the browser from the server when it read our file.
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Troubleshooting
  5. PHP View Source - PHP Code Hidden - View Code Source

©2013 About.com. All rights reserved.