Join Kevin Skoglund for an in-depth discussion in this video Introducing single-serving sites, part of Easy PHP Projects: Single-Serving Sites.
- Websites don't have to be complex. In fact, sometimes simple websites can get the job done or make a point effectively. In this course, we're going to take this idea to the extreme by looking at what we can do with websites which are made up of only one single page. The phrase coined for these miniature sites is single-serving site. A single-serving site is a website with a dedicated domain name which serves up only one HTML page.
And that page does exactly one thing. They can have practical applications, or they can just be for laughs, but they always keep it simple out of necessity. I've always had a soft spot in my heart for single-serving sites. They're a refreshing contrast to sites that load themselves up with features and try to be everything to all users all the time. Single-serving sites are focused, and easy for everyone to understand. They have a certain purity about them that I admire. The oldest single-serving site is probably Purple.com, which was launched in 1994.
This website contains no links, and it's only content is a purple-colored background. Purple.com is still online today, and you can go there and take a look. The site simply shows the color purple, as you'd expect from the URL. But this page is just static HTML. By adding a little code, we can make a single-serving site dynamic. Here's a similar well-known site called SometimesRedSometimesBlue.com. If you go there and you reload the page a few times, you'll see that sometimes it's red, and other times, finally get there, it will reload to blue.
It's the same idea as Purple.com, but this one is dynamic, even if only a little bit. Okay, so neither of these examples is very exciting. It's kind of fun to see that someone dedicated an entire domain name to these sites, but they're probably not sites you'd want to visit regularly. In general, single-serving sites fall into a few common categories. There are random displays, sites that answer a question, useful tools, works of art, and jokes. I would say that Sometimes Red Sometimes Blue counts as a random display.
Maybe you could also argue that it's a work of art or that it's a joke site. Let me move from these simple examples to show you one of my favorite single-serving sites, that I think you'll find more interesting, in which shows a single-serving site doing what it does best. The site is HowManyPeopleAreInSpaceRightNow.com. It's a very long domain name, but you instantly understand what the site is about. It's a site that tells you how many people are in space right now. And if you go to the domain HowManyPeopleAreInSpaceRightNow.com, you'll see that it tells you the answer.
Right now, at the time that I'm recording this, the answer is six. Now, it doesn't just tell you the number, we can actually scroll down and find a bit more information that tells us who is in space and how long they've been there. But that's really it. That's what the site does. It tells us how many people are in space right now, and a little bit more information about them. There's not a lot of other pages, not a lot of other features, it simply answers this one simple question. A question that I find pretty cool and interesting. Here are a few other single-serving sites that you can check out on your own.
These mostly fall into the answering a question and useful tools categories. There's WhatColorIsTheEmpireStateBuilding.com, which tells us what color the Empire State Building is tonight, and on previous and future nights as well. There's DoINeedAnUmbrella.com, that will tell you, based on your local weather, whether or not you need an umbrella. PriceOfAStamp.com, to tell you the price of a stamp. DownForEveryoneOrJustMe.com. This is a website that I actually use a fair amount. What it's for is if you have trouble reaching a website, and you're wondering, is that website down for the entire Internet or is it just down for you for some reason? Are you having trouble reaching it? You can go to DownForEveryoneOrJustMe.com and it will try to remotely load up that same website to tell you whether or not they're also having trouble reaching that server.
And then there's ASoftMurmur.com, which, as you would expect, allows you to play a soft murmur from this single-serving site. There are a few more that would fall in the joke category. I'm going to give you the domain names for those, and then we'll go take a look at them. The first is another very long domain name. HasTheLargeHadronColliderDestroyedTheWorldYet.com. And then there's LMGTFY.com. That's an abbreviation for "Let Me Google That For You." And PointerPointer.com, which I want to also note loads up random Internet images.
I've never had a problem with those images, but because they are random images from the internet, there is the possibility they could be not suitable for work. Let's take a look at these in Firefox. The first one, HasTheLargeHadronColliderDestroyedTheWorldYet.com, loads the answer, "Nope." We can hit return as many times as we like, and it says, "Nope," to us every time. Now, the joke here, of course, is that if the Large Hadron Collider had destroyed the world, well then, this website would disappear, so it always says "Nope." And then there's LMGTFY.com, or Let Me Google That For You.
If you've ever had someone who's asked a dumb question, something that they probably should've just gone to Google and figured out for themselves, well, this is the site for you. This allows us to give them a link, but also to sort of passive aggressively respond to them that they probably should've just Googled it for themselves. So, for example, if someone asks, "What is a single-serving site?" you could come to this site, type in "single-serving site," hit Return, it'll create a link for you, and now we could just copy that link, and I'm going to paste that up here.
It's the same URL, but just with a Q = after it. Right, the /?Q=, and then single+serving+site. That's all it is. So it creates that link for us, if we visit that link, it comes to this same page, but this time it goes and it types it into the box for us. Then it tells us Step 1, Step 2, and it says, "Was that so hard?" It Googles it for us, and it gives us the page of Google results telling us about single-serving sites. And then let's take a look at Pointer Pointer.
So if you visit Barack Obama Is Your New Bicycle, it'll give you a random phrase such as "Barack Obama Paid Your Speeding Ticket". We could reload the page, we also can click the link here, and we'll get "Barack Obama "Set Your Voice As His Ringtone." He carried your bookbag, all sorts of nice things, he loves your laugh, he said he really wanted to meet you. All these nice things that it says about Barack Obama. You may have actually seen this website before. The website became wildly popular for a brief period during the 2008 election, and there have been many imitators of its style since.
Here's what the creator, Mat Honan, said about the site: "There's a PHP script with a bunch of phrases. "The index page just calls up a new one "at random every time someone loads "(or reloads) the page. "The linked text just points right back at "the main page, so when you click on it, "you're really just refreshing. "In the first seven days, 140,000 people visited the site, "with 2.3 million page views (keep in mind it's "a single page site so that's a lot of refreshing)." All right, 2.3 million page views.
Just let that sink in for a moment. He says, "I was definitely influenced for the idea of "how it would work from Andre Torrez' site, "as well as Sometimes Red, Sometimes Blue." Which we saw earlier. So with just a little bit of PHP and a lot of creativity Mat created a phenomenon. The possibilities are limited only by your imagination and creativity. In the following movies, we'll create a few single-serving sites of our own using PHP.
- Finding and validating an IP address with PHP
- Parsing the HTTP request for browser details
- Comparing dates and times in PHP
- Randomizing data with PHP
- Styling page content dynamically
- Generating random sentences