Create the following html page but save it as test.php instead of test.html. Upload the file and view it on the server.
<html> <head> <title>Hello</title> </head> <body> Hello World! </body> </html>
When a request for a page with the extension html is received by the server, it retrieves the page and returns it as is to the requestor. When a page with the extension php is received, it retrieves the page, executes any php code, then returns the result. That is, php is executed on the server, whereas javascript code is executed on the client. That means that, unlike javascript, no one can see your code by looking at the page source.
Right now, there is no php code in our page. Let's replace the line "Hello World!" in the body to display the same message using php:
<?php echo "Hello World!"; ?>
Upload the file and refresh the page. The page should look exactly the same, but now it is using PHP to display the message.
Each of the examples is saved with the extension .php and with the extension .html. Click each of these links, then look at the page source. In Firefox, select View, Page source from the menu or type CTRL+U. In Internet Explorer select View, Source from the menu.This will let you look at the PHP code because the server only interprets the PHP code if the extension is .php.
Example 1: hello1.html, hello.php (Note that both pages have exactly the same contents, only the extension was changed.)