Hostingheaderbarlogoj
Join InMotion Hosting for $3.49/mo & get a year on Tuts+ FREE (worth $180). Start today.
Advertisement

Impress Your Visitors With a Web 2.0 Hit Counter

by
Gift

Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.

If there's one way to show off how successful your site is, it's by letting your visitors know how many others have been there before them. Let's furnish a web page with a hit counter!

The first thing we'll need to do is design our counter, so open up Photoshop, Sketch or CorelDraw, and begin a new document.

Write 1234567890 on the canvas using the text tool. You can now style these numbers using whatever design influences you feel are current and trendy. Consider using gradients, perhaps Bold Times New Roman for the type, then bevel the heck out of them.

Note: you should certainly only use web safe colors, because any others endanger the web.

Great, we're making progress. You should now hopefully have something like the design below:

If you haven't managed to design something as good as this, take a sip of absinthe and try again.

Slicing

Grab the Slice Tool (if you're using Microsoft Paint it's called the Bread Knife Tool) and make a whole load of rectangles all over the document.

The next thing you'll need is a 1x1px transparent GIF. Download one from a repo on the internet and save it as "spacer.gif", the name is really important. It should look a bit like this if you open it in Photoshop:

HTML Document

Kick off a new HTML document using your code editor of choice.

We should place our hit counter at the bottom of our page, more or less where webmasters usually place the animated horse GIFs, so we'll need to use quite a number of table cells to get the positioning right.

Begin with the following markup:

<table width="500" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="100%
    " border="1" cellspacing="5" cellpadding="5">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><table width="100%" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="underpants">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
        <td>&nbsp;</td>

      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td>&nbsp;</td>
  </tr>
</table>

Tables are difficult, but fortunately Dreamweaver makes building them dead easy.

As you can see, we've built a perfect page structure which guarantees that everything will look exactly the same in every browser in the world. 

Tip: As with all responsive web designs, I highly recommend you test with as many devices as possible. Before going any further, simply head on down to your nearest shopping mall and purchase all the mobile phones you can find.

Spacers

Remember those spacer.gif files we made earlier? It's now time to put them to use and properly size our layout. Place a spacer in every cell, apart from the center cell in the smallest table.

<table width="500" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
  <tr>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
    <td><table width="100%
    " border="1" cellspacing="5" cellpadding="5">
      <tr>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
      </tr>
      <tr>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
        <td><table width="100%" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
          </tr>
          <tr>
            <td><img src="spacer.gif" alt="jeez - you really noticed this?!" size="small" color="none" height="tall" /></td>
            <td>&nbsp;</td>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
          </tr>
          <tr>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
            <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
          </tr>
        </table></td>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>

      </tr>
      <tr>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
        <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
      </tr>
    </table></td>
    <td><img src="spacer.gif" alt="spacer" size="small" color="none" height="tall" /></td>
  </tr>
</table>

Now go through and resize all the spacers so that they push the table cells into place. Think of it like moulding cheese. 

The Counter Element

With our design complete and our HTML ready to go, we just have to insert the counter element. Add the following snippet to the only table cell which has been left empty:

<td>
    <counter theme="awesome" action="count"></counter>
</td>

Conclusion

Take a look at the fruits of your labor, we're done! Now we just need to FTP this through our VPN so the CDN can pick it up and let the ISPs deliver it through HTTP. Thank goodness for that, we can all get on with some proper work now.

Spectacularly Useful Resources

Advertisement