Why Don't I See My PHP Code When I View Source?
Why saving a PHP page from a browser doesn't work
Updated on February 26, 2019
Web developers and others who are knowledgeable about web pages know you can use a browser to view the HTML source code of a website. However, if the website contains PHP code, that code is not visible, because all the PHP code is executed on the server before the website is sent to a browser. All the browser ever receives is the result of the PHP embedded in the HTML. 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.
PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.
Sample PHP Script
When this script appears in the coding of a web page or .php file that is downloaded by an individual to a computer, that viewer sees:
My PHP PageBecause the rest of the code is just instructions for the web server, it isn't viewable. A view source or a save simply displays the results of the code—in this example, the text My PHP Page.
Server-Side Scripting vs. Client-Side Scripting
PHP isn't the only code that involves server-side scripting, and server-side scripting isn't limited to websites. Other server-side programming languages include C#, Python, Ruby, C++ and Java.
Client-side scripting operates with embedded scripts—JavaScript is the most common—that are sent from the web server to a user's computer. All the client-side script processing takes place in a web browser on the end-user's computer.
Hello friends. Maybe many of us are already familiar with what a programming language is and in particular what is PHP programming language. this time we will continue a discussion about the basics of PHP programming. let’s go straight to the first discussion.
Executing Source Code
How to Execute PHP Source Code
We start from this discussion.
- first, we have to Create source code with a text editors like Sublime Text or Notepad++.
- and then Save the source code into a file with a .php extension in the C:/xampp/htdocs folder.
- Open the xampp application and click start in the Apache section.
- Open a web browser. Enter the address /localhost/htdocs/filename.php. Filename.php is the file that contains the source code saved in step 1. Don’t forget to write the .php extension after the filename.
The picture above is the result of the execution of the PHP program in which there is also the HTML language. The server will read or detect the PHP code When the server finds the <?php tag and ends When it finds the ?> . tag
Both scripts produce the same display. The difference lies in the way the PHP source code is executed.
Note :The picture above is an example of the HTML language that is loaded using the PHP script
Conclusion
We have come to a conclusion. The conclusion from our discussion is The PHP file is stored in the c:/xampp/htdocs folder so that it can be executed. and then run apache module on xampp application to start execution. We will continue our discussion of Basic PHP in the next article. I hope this article can be useful.
Thank you.