Red Winged Black Bird on a fence post in a field.

How Web Programming Works


Category: crafts

Lately I?ve been asked by a few people, on separate, occasions, to explain how web programming works. Some of these people were programmers in their own right but had never programmed for the web. Others were just curious people. I figure there are probably more people out there who may be curious. That?s why I?m writing this.

This discussion will be kept simple and abstract so that any one can understand the concepts. If you?re an old pro at this sort of thing, this will be way beneath your level of understanding. I?ll try not to be too boring.

To start, when you go to the internet you probably use a web browser such as Internet Explorer or Mozzilla Firefox. In the programming world, this kind of software is called a web client. The word client is used because it is similar to the way a business client is treated. It asks for something the business provides and the business provides it.

So you open your browser, open your list of favorite sites and click on the name of your most favorite porn site. Your browser program realizes that you want to see what is at that site. The browser creates a text request that includes the URL of the porn site and sends it out into the internet.

The name URL means Universal Resource Locator and it is the in the form of a number with dots in it or in the form of a domain name. You may have seen the dotted form which will appear as where the numbers between the dots can be any number between 0 and 255 inclusive. (As a side note, as a matter of protocol any computer will refer to itself as or with the name localhost.) A domain name is the text name such as which actually gets looked up in a computer somewhere and translated into the dotted number format.

Out there in the internet, at the address you specified there is a thing called a server. You will hear people call a computer a server. Technically, it is the software that is the server and any computer that is capable of running the software can be the server computer. You will see why the software is called a server shortly.

The request your browser sent arrives at the server. The server looks it over and decides what to do. There are many options available. It may deny your request. It may redirect your request to another server. Most often though, it will try to honor your request and give you what you wanted.

One of the first things the server must do is figure out what it is you want. It will look at the last few letters of the page you requested. That tells the server the sort of thing you are after. Some examples may be:

HTML:A normal web page
HTM :Also a normal web page
Asp :Active Server Page (Microsoft Technology)
Jsp :Java Server Page (Sun Technology)
PHP :A page written using the language php

Once the server knows what sort of page to send, it can find the page and send it to you. The simplest example is the HTML page. These pages are static, meaning that once they are written they do not change on their own. The letters HTML mean Hyper Text Markup Language and the page is just text with instructions to draw a page. The server finds this text file and sends it back to your browser. Your browser then draws the page on your screen using the instructions included in the HTML file. The same applies to pages with names ending in HTM.

The other type of page is called a dynamic page. This means the page can change as needed by the request and the available data. You have probably gone to a web site or two where you have to log in and then it gives you information tailored specifically to you. These are pages that change.

Let?s look at an example. Imagine that you go to an airline website and ask for the arrival time of your lover?s plane. The site says the plane should arrive at 3:00 PM local time. Naturally, planes are always late. You check the website again. Even though you asked for the exact same page, it now says your lover?s plane will be in at 4:00 PM. You have one more hour to be with your other lover.

Why did the same page have different data? Well, that?s what dynamic pages are all about. It involves a data source (like a database), a normal page to use as a template, and a programming language. Regardless of which type of dynamic page is used, they all follow this procedure.

The LibertyBob web site uses PHP so I?ll use that as an example. When you click on the comments link below an article, you tell the site to open a new little window and fill it with the existing comments as well as a form where you can add comments of your own. Opening the window is just a script that works in your browser and we?ll ignore that for now as being off topic.

That little window is a new browser window and it has a request for the LibertyBob Server. The request basically says, ?Hey, Server, give me the comments page for the article called Why LibertyBob is Hot.? The request makes it to the server. The server looks at the tail end of the page name and realizes that it?s a PHP page. The server then says, ?I?ll give this to the PHP engine.?

You read that right. There?s a PHP engine out there at the server. In the case of ASP or JSP, there are ASP engines or JSP engines as well. These engines are programs designed to run programs at the request of a web server. The server can?t run these programs itself; it?s not that kind of program. These added on engines are needed.

In our example, the PHP engine gets the request you sent and tries to run the program that you requested. Now, the comments page has two possible states; either you want to look at the comments or you have submitted a comment. The PHP program looks at the request and decides which. If you have submitted a comment, it takes that comment apart into who sent it, their email address, their URL, and the text of the comment itself and stuffs all that into the database. After that, it does the exact same thing it would have done it you had only wanted to look at the comments.

To show the comments, the PHP program does two things. First, it asks the database for all the comments for the given article. If you just added some comments, those will be in the batch. This information then gets put together as text that is formatted to go on an HTML page.

You?ll remember from earlier that HTML pages are just text. That?s important. The PHP program next opens a text file that is really an HTML page. The file tells how to draw a comments page for the LibertyBob website. The only things missing are the title of the page and the comment text. Instead, the is a bit of text in the file called ?Title Goes Here? and ?Comments Go Here? that are set up so your browser will ignore them.

The PHP program does not ignore those bits of text. Instead, it reads through the file and replaces those bits with the actual title and the actual comments for the article. When this is done, the PHP engine hands the completed page to the Server which then sends the page to your browser. You then see the comments for the article, including your own if you just added some.

That?s how internet programming works. For more details, you should visit the W3 Schools. The W3 Consortium is the non-profit organization who sets standards for the internet all over the world. The W3 Schools offer FREE, on-line tutorials for all the web technology and you can learn how to do all the things I described above. If you would like to make your own web pages, databases, or dynamic web site, their FREE tutorials are just the thing, whether you?re a beginner or have some skill.

Please enjoy the internet and all it has to offer. (Ok, maybe there are some parts of the internet to avoid?) If you have any questions or comments, let me know. If you get a chance, please play with my Comments feature. I had a lot of fun writing it and hope you find it easy and convenient to use.

Comments (6)
You gotta pick the right guy to do the job.
Go out now and vote for LibertyBob.
True freedom comes from reason.