Understanding PHP & the Web Server/Browser Relationship
One of the tricky aspects of PHP is that each time you make any sort of request on the web page, the web browser will then open a connection to the web server, which will then process the request and send back a response. The connection to the server is then closed. This makes web programming different than other types of programming in the sense that you will need to use sessions in order to keep track of the state of the application. You will need to constantly reload and update these variables and pass them on as the user continues browsing the page. I’ll talk more about sessions and sessions variables later this week. The first thing that is important to understand is what is going on behind the scenes!
- First things first, the user opens up his/her browser. This you will soon find, is actually the source of much evil and many headaches as no one browser will interpret your web page the same.
- Next, the user types in the address to your website, or clicks a link to access your website. In so doing, a name server will then direct your browser to the server hosting your web page.
- The server hosting your web page will receive the request and retrieve the page that was requested by the browser.
- Since the page the server retrieves is a .php page, the server will compile the page using a just-in-time compiler that in turn generates the HTML code which is what is then sent back to the browser which made the initial request for the page.
- Lastly, the broswer receives the HTML code and displays its interpretation of it, which will often vary from browser to browser.
Users viewing your page will not be able to see your PHP code. This is because the server compiles the code and generates HTML which is sent back to the user. Because all of this takes place server-side, the user can only view the HTML source to your page.
Leave a Reply