How Web Applications Work
2 min readDec 12, 2018
Occasionally I get asked to answer questions on Quora and other networks, and often there are questions asking why someone cannot read a website’s PHP or [insert scripting or server language here] source code. The simple answer is that what is sent back to your computer or device’s browser is usually just HTML content that the browser reads (or some other format of data like JSON, XML, etc.). To help explain how a web application is assembled, I prepared the following in hopes it helps others better understand what is happening.
- Your device or computer is connected to the Internet and your browser requests a URL (yahoo.com/finance.php)
- Your device connects to the public Internet via your ISP (broadband or cellular provider) and tries to find the address for yahoo.com via DNS lookup which is like a phone book for network addresses to computers connected to the Internet. It allows a look up by [domain] name and returns an IP address like 55.55.55.55, just like your name might return your phone number in a phone book. This is the network address of the computer that is hosting that domain.
- Your request is transmitted through the Internet to the IP address you found similar to typing that number in your phone and placing a call.
- The computer connected to that IP address would have web server software running on it that will go fetch the requested file, and send it back. (a) if just a .html file, the server finds it on the computer and sends it back. (b) if a .php file, the web server knows to hand off the request to the application server that will process the PHP code.
- The application server receives an HTTP Request from the web server, finds the file with the source code (programming instructions) for that web address (i.e. finance.php), and executes your PHP program.
- The program references a connection to a database server (just another program run on the computer) and sends it a “query” to request data stored and organized by the database server.
- The database server fetches the files requested from the query.
- The database server sends back the requested data to the application server.
- The application server combines this data with any other data your program instructs it to add, and sends it all back to the web server as an HTTP Response. Typically you just output HTML-formatted text but your program can inject data into it as it loops, etc.
- The web server sends back the HTML text to the requesting connection.
- The data is transmitted over the Internet back to your computer or device and the connection ends.
- Your device browser reads the HTML code (that was generated) and displays it on the screen.