Categories
Networking Operating Systems

Setting up a DNS Round Robin in Windows

A round robin lets you load balance by pointing the same host name to multiple servers in DNS.  As long as round robin service is enabled in the DNS server, incoming requests will be spread among the servers.

Following is the short version of how to do this.  For a more comprehensive look at this, see Rodney Buikes excellent article on the subject.

  • In the DNS Mgmt application on your DNS server, right click the server name in the tree in the left pane, select Properties, select the Advanced tab, ensure that ‘Enable round robin’ is selected.
  • Add HOST(A) records in the appropriate forward lookup zone, pointing to the servers to be covered.
  • If you want a little poor-man's fault tolerance, ensure that the TTL of each record is set to a short period of time, i.e. 15 seconds.  This ensures that if one of the servers fails, repeated attempts to connect will soon hit another server.
Categories
DHTML JavaScript

Sortable Tables with JavaScript

For years I've fiddled with trying to make my tables sort in JavaScript.  The user can simply click on the column header to make the table sort on that column.  Click again and it sorts the other way.

There were various scripts out there to do it, but I never had the time and need all at once to get one to work.  None seemed to really work well, or they weren't documented well.

Now I've found it. This one works right out of the box. It's well documented on the page, but here's the gist of it;

To make the Javascript available to your pages:

  • Load the sortabletable.js file into your site.
  • Reference the script in the <head> section of your pages.

Now make the following modifications to the pages with tables;

  • Wrap the row that contains your column headers with <thead></thead> tags.
  • Make sure the row with the colum headers used <th></th> tags instead of <td></td>.
  • Wrap the rows that contain your table data with <tbody></tbody> tags.
  • Add an id="MyTable" attribute to the <table> tag for each table you want sorted.  Of course, the id must be unique on the page.
  • Place the sortable table object immediately after each sortable table.  It's shown in the sample code on the site, easy to place with a simple cut and paste, but remember to replace the 'MyTable' string with the id you used in that table's <table> tag.

That's it!  The table now sorts.  Sweet.

Here's where to find it:

While you're there, remember how whoever runs that site pays his or her bills.

If you're not familiar with the very helpful but little used <th><thead><tbody> and <tfoot> tags, Google them.

2009-04-04: Late News: There's a more advanced table sorting method in this frequency-decoder.com article.

2009-08-10: Late News: And now this great script at yoast.com that has alternate row colouring in the javascript, so that it sorts properly.

Categories
Security

Online Hash Generator

This online hash generator will quickly generate MD5, SHA1 and SHA256 hashes.

Not much more to say.

http://hash-it.net/

Categories
Database MySQL

Re-numbering an auto-increment column

An auto-incremented column can become a little cluttered if records are deleted from the table, and you may wish to delete the slack of the sequence in your id column for instance doesn't bear any relationship to the number of records in the table.

Before doing anything about that to a primary key, bear in mind that there are those who say that a primary key should never, ever be changed.  Do you really need to re-number your primary key?

If you really want to do it, read the caveat below before proceeding.

CAVEAT: I haven't actually tested this!

First, be safe and backup your database.

Next copy your table:

CREATE TABLE mytable2 SELECT * FROM mytable1

Now run the following commands, modified as necessary for your situation, on the copy:

ALTER TABLE mytable2 DROP mycolumn;
ALTER TABLE mytable2 ADD mycolumn int(6) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

Have a look at the new table.  Browse the records.  Do you like what you see?  Run as many tests as are appropriate to your situation.  More is better than less.

If you're satisfied, it's time to disable mytable1 and make mytable two current.

Rename mytable1 to mytable1_old, then rename mytable2 to mytable1.

Keep a close an eye on the situation.  If you're not happy, you can revert to mytable1_old or even restore the backup.

Categories
PHP

Securing your PHP Code

It's easy to overlook security when we write PHP code, yet failure to write code with security in mind can result in catastrophe.

Rather than write the book myself, this is one of those cases where we should just reference some good material written by others.