29 Aug 2010

Guide for Newbies -- How Web Forms & The Internet Work

Internet

You probably don't care about specifics on how the Internet works. When you sign up to a web page or update your Facebook profile, you simply assume that the guys behind the page figured it out, and you just expect it to work. I figured I might as well shed some light on how your information is being transmitted and stored, so you can at least hold up a conversation when surrounded by geeky talk, and know what is truly going on when you do fill out forms on the internet.

There are a lot of different browsers out there, Firefox, Google Chrome, Internet Explorer, Safari, Opera, the list goes on. Most of the browsers have drastic differences in how their core works to render a website for your viewing pleasure. But they all are supposed to follow standards on how to display data (I say "supposed" to because older versions of Internet Explorer made their own standards and cause problems for all developers building webpages). More or less though, most of the time a webpage will look almost identical whether you're using one browser or another. So your computer is connecting to a website that you type into your browser. For example, when you type in www.google.com, your browser communicates with Nameservers to resolve that host to an IP address. Usually these Nameservers are set up by your Internet Service Provider (ISP), and are dedicated to just do hostname resolving, so you don't even realize they're there. So let's assume that www.google.com resolves to IP address 72.14.204.147 (try going to http://72.14.204.147 just to see that it does in some cases). Once your browser finds that IP address, it connects to it. To connect to another computer, the other computer needs to have a port open, which is basically a communication channel that accepts other computers to connect to it. In the case of webpages over HTTP, it's by default on port 80. So you're actually connecting to http://www.google.com:80 or http://72.14.204.147:80 . Now, once you're connected, your browser sends some information. That information usually includes the version of the protocol your browser is communicating in, the URL of the page you're trying to access, the communication type [GET (to retrieve a webpage) / POST (to send data over to a webpage) / HEAD (to see the server's headers)], your User-Agent (which is your browser name), the type of content you accept, and your cookies that you have associated for that URL or domain. Once that information is sent over the other ends replies with the content of the webpage, which may be dependent on the information your browser sent. For example, if your browser was sending a cookie which indicated that you were logged into an account, it would send you a page where you were logged in to your account (i.e. Facebook). If you weren't logged in though, it might send you to a login page to ask you for your email and password to continue. Once you fill out your email and password, this connection is initiated again. When that connection is secure, it happens in a separate way which encrypts the data you're sending over, so someone who's on the same wireless or local area network as you can't "sniff" around and see the information you're communicating. Now that you sent in the usual info (above) as well as your email and password, the website checks against its database (this is done automatically through code created by programmers), to see if it's a real account (as well as other security measures), it creates a session on Facebook.com and sets a cookie on your computer. Every time from then on, when your computer connects to Facebook.com, it sends that cookie over to confirm that you're logged in, and you're able to access your account. Anything you do from then on to update your profile or browse the website is done through the same method of sending and retrieving data.

It gets a lot more complicated on the backend depending on the complexity of your website, but at least you now know what's happening when you browse the internet (if you didn't before).