Why Browser Sniffing is a Bad Idea

For many web developers, browser sniffing has become almost routine. Have you ever noticed that short list of “supported web browsers”?

While browser sniffing may seem like a good idea at first, you may be setting yourself up for problems later.

The biggest problem with browser sniffing is that it is usually relied on far too heavily to even consider removing later. The inner workings of a site can be based (unknowingly sometimes) around working specifically for specified web browsers and nothing more.

One poor use of browser sniffing that I came across today was for EyeWearSelect.com and it just so happens to be an easy fix.

On one of the EyeWearSelect pages, they show a thumbnail preview of a pair of glasses. Below the image is a link entitled “Click to Enlarge”, which uses some javascript to show you a larger picture in a pop-up window. Here’s how they begin the pop-up script..

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}

Basically, the script says…true or false…this is Netscape? Also, true or false…this is Microsoft (Internet Explorer)? ..but what if you’re not using Netscape or Internet Explorer? What if you’re using Opera? or Konqueror?

If you’re using a browser that doesn’t match Netscape or Internet Explorer, then the future checks for isNN and isIE will never match and your browser will be “incompatible” with the scripts. In this case, the incompatibility is that the author never made it possible for those that are compatible.

A simple fix for this would be to change that bit of code to the following, which would basically check for Internet Explorer and then treat all others differently..

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
var isNN=!isIE;}

They won’t always be this easy for developers to correct, but this script could actually be cleaned up much more than just that.

In most cases, browser sniffing isn’t needed. The more efficient method to follow is capability testing.

If your code requires a web browser with capabilities that others (or not all web browsers) have, then you can use browser sniffing which is a form of hard coding the compatible web browsers…or you can test the browser’s capabilities and see if the javascript that you need to use will be supported.

By using the second method, you make your script much friendlier to the future of both the web and it’s browsers. You will also save yourself some work by not having to update the script each time you want to support another browser that would already be capable of using your script if it weren’t blocked in the first place. 😉

If you run compatibility tests and find that a certain feature will not be available, that’s the time to announce that the user should update their browser or use a different one all together.

Of all of the times that I’ve seen browser sniffing, only a couple have every been properly used. One of those was a browser sniffer that would display instructions and images explaining how to download and save a file to your computer. The images were of course specific to the browser that I was using for a more useful set of instructions.

If you should happen to come across a web site that suggests that your browser is not compatible, fire off an email and let them know that you would appreciate more accurate scripting and detection for your web browser let them know that you would appreciate more accurate scripting!

Quick Linux Copy/Paste Tip

This is just proof that you can learn something new about Linux everyday.

So, are you tired of trying to copy and paste information from one source to another by means of pressing Ctrl+C and Ctrl+V? Or better still, by right click -> copy and right click -> paste?

Well, there’s a much easier way to do this. No seriously! I just found out about it myself after trying to track down where this bug or accidental copy-n-paste was coming from.

Once you learn to use this, however, it becomes very useful and will most likely replace your keyboard shortcut method. It may even be a cool trick you can tell your friends about. 😉

You see, normally if you want to copy text or anything else from point A to point B you will be using a copy method that stores that data into the clipboard, holding it until it is replaced by the next copy.

With this method, oddly enough, what you already have stored in the clipboard is not altered at all!

The method I’m talking about is copy-n-pasting via middle clicking (that scroll wheel on your mouse of course). Here’s how it works.

When you select any text (any text at all) in Linux, you may not know it, but it is being stored in a clipboard of it’s own. To access that clipboard to paste from it, all you have to do is middle click!

To try this out, select the text here in bold red and press Ctrl-C or right click -> copy. This stores that text in the clipboard that you’re used to.

Now, select the text here in bold blue (it doesn’t matter if you leave it selected or not, it works either way). Now, go down to the comments section of this post and middle click in that text area.

If you’re in Linux you’ll most likely see that it pastes “bold blue” into the text area (color and font weight won’t appear in that simple text area). Now press Ctrl+V or right click -> paste and you should see that it pastes “bold red” into the comment text area!

If you see both items pasted into the text area, then that means you can take advantage of both clipboards as well as a faster method of copying data!

It may take a little time to become familiar with it, however, I’ve not been using it long at all and it’s already nearly replaced the old method for me entirely!

How-To: Digsby+Wine

After getting back into the Digsby scene again I decided it was time to get Digsby running in Ubuntu. I grabbed the latest installer and was well on my way.

I’ll just break down the steps so you can follow along. Depending on the distro that you are using, these steps may vary.

  1. Install the newest version of Wine that you can (in my case I just went with Wine 1.0).
  2. Open up a terminal window and enter the following lines (one at a time 😛 ):
    wget http://kegel.com/wine/winetricks
    sh winetricks corefonts dotnet20 gdiplus
  3. As a safety measure (it may not make a difference at all) I opened the “Configure Wine” application and set the default settings Windows Version to “Windows 2000”. This has seemed to help make applications work in Wine in the past.
  4. Now download Digsby. I used the latest version which was for testers and should be released very soon. So for now just grab your installation from here.
  5. Install Digsby. In most distros of Linux you can just right click on the install file and click Open with “Wine Windows Program Loader”. Follow the steps through the installation and launch Digsby. Everything should be working now!

Basically all you had to do was install the .NET 2.0 framework and gdiplus. I’m not positive on corefonts, but they will only improve compatibility.

Everything seems to be working great! I notice some odd behavior here and there, but the application itself is working great! The only thing that is a bit annoying is that Facebook will occasionally disconnect, but it immediately reconnects. 😀

How-To: Share your Internet connection between multiple computers (Ad-Hoc)

If you’ve ever been in a situation similar to mine where you have multiple computers, one Ethernet cable and no wireless router then don’t sweat it. You’re still in luck!

If one of your computers has at least two network cards, for example an Ethernet port and wireless capabilities, then you can connect one computer via the Ethernet connection and broadcast that same connection over that computer’s wireless card so that other computers can connect. I’ll show you how below.

I will be walking through the steps in Windows Vista, but the steps should be the same across all platforms. If you’re using a different platform then just try to find the same dialogs and options on that system and everything should work fine.

  1. Open the Control Panel. To do this, go to Start->Control Panel
    If you’re in Windows Vista and your Control Panel window looks like this:

    You will need to click on the option labeled “Classic View” in the upper left corner of the window. This will change the layout of the Control Panel so that I don’t have to rewrite this How-To in multiple different directions. After changing the layout, your Control Panel should look like this:
  2. In the image above, the icon for “Network and Sharing Center” is selected. Double click on this option. When the window changes you should see a list of tasks in the left column. Click on the item from the list labeled “Manage network connections“. This will open a new window that should show the network cards available on your computer.
  3. Make sure that your Ethernet cable is plugged into your computer and your Internet source and that the Internet connection is working fine on that computer. Now right click on the option labeled “Local Area Connection” and select “Properties” from the menu (User Account Control will most likely ask you if you wish to continue and just agree and click continue if it does).
  4. The Properties window will open on a tab labeled “Networking” with a list of items that the connection uses. Just ignore all of that and switch to the tab labeled “Sharing.” The options on the “Sharing” tab should be selected as follows. Enable the option labeled “Allow other network users to connect through this computer’s Internet connection.” Disable the option labeled “Allow other network users to control or disable the shared Internet connection.” After matching these settings, click “OK” to save the changes.
  5. You can now close the window for “Network Connections” and reopen the window for “Network and Sharing Center.” If you have already closed this window by accident then you can follow steps 1 and 2 again, except this time instead of clicking on the option to “Manage network connections” you want to select the option to “Setup a connection or network.
  6. When the “Setup a connection or network window opens, it will have a list of networks that you can setup. The one that you want to setup is selected in the image above and is labeled “Setup a wireless ad hoc (computer-to-computer) network. Setup a temporary network for sharing files or an Internet connection.
  7. When the “Setup a wireless ad hoc (computer-to-computer) network” window is open, it will explain a little bit about the network. Just click “Next” until you get to a form that is empty and looks like the form below:

    You need to give the network that you are creating a name that you will be able to recognize and it can be anything that you want!

    You also have the option to add security to your network. I highly advise this as you have more control over your network, so just select the option for “WEP” and below it enter some form of a password.

    You can click the option to “Display characters” while you are entering the key/passphrase. This will make it easier to make a new key for your network.

    Don’t forget to also enable the option to “Save this network” if you plan on using it later!

    If you hover the text box for the key/passphrase, you will see a notification tooltip that explains how the passwords work. You should follow those instructions to create your password and make sure it is the correct length as specified in the tooltip.

  8. Click “Next” to complete the setup and close any open windows. Your Ad-Hoc network is now setup and you should now be able to see a wireless signal on your other computers. Connecting to your network will require the users to know the key/passphrase that you entered, but once connected..all of the other computers should be able to browse the web and connect to instant messengers…anything you need!

If you have any questions then please ask them in the comments! Just remember to follow the steps closely before asking. Enjoy!

[solved] Stop WordPress Spam Registrations

I’ll bet all of you out there have dealt with your fair share of spam. Everyone gets it, in their email, blog posts and lately even WordPress registrations! I have a tool for handling spam comments on my blog, but what do I do when I get 10’s to 100’s of spam user registrations on my blog with names and emails like BuyCheapMeds and FreeSoftwareDVDs@some-russian-website.ru?

Well, thank goodness the WordPress Extend site has so much to offer! After asking in the WordPress forums how to completely disable new user registrations…and getting little response…I decided that I would have to edit some of the WordPress files to ignore new user registrations in a fashion to fit my needs. I wanted to keep them open from the admin panel so I myself can add new users, but block outsiders from registering so I could control the spam registrations.

To my surprise I got a response in the forum thread that I started with an example plugin that could be used. I looked into the example plugin, but I found myself confused at the description and uncertain of how the plugin actually worked. Who wants to install something on their site when they have no clue how it works!

I dug a bit deeper and searched this time for only 5-10 minutes and came across two plugins that were capable of handling my needs and one that was just plain cool.

To control your spam registrations I would suggest the following three plugins which are ordered according to the order that I would choose them.

  1. Register Plus
    http://wordpress.org/extend/plugins/register-plus/
  2. Sabre
    http://wordpress.org/extend/plugins/sabre/
  3. Referrer Bouncer
    http://blog.taragana.com/index.php/archive/word-press-1-5-plugin-referer-bouncer/

If you’re wondering why I sorted them this way then I’ll try to explain quickly.

Referrer Bouncer was the one that was suggested to me in the forum thread, but I found that it was a bit more involved than the others and it required the user to create a file called “referer.txt” and add domains that should be blocked (at least I think it was for blocked domains…not a clear description or how to 🙁 ) and it just made more sense to go with a different plugin rather than tracking down all of the referring sites that I needed to block.

Sabre does exactly what I wanted to do. It was like it knew what I wanted before I asked, haha, but I decided to go with Register Plus in the end because it allows me to create invitation codes so that I can easily leave the registration open to the public, but they will need to contact me and request an invitation.

Why did I chose this method? I figured that most people would prefer not to register in the first place. Nothing at kyleabaker.com is restricted to the general public that is open to the registered users…it’s all the same. So if you wanted to post then you can freely post comments here. The invitations are for friends and people that I know so they can register if they wish and I know they won’t be spamming me. 🙂 Except maybe Dan…he’s done it before. 😛

The third plugin that I found (the Referrer Bouncer was found by someone else and posted in the WordPress forums for me) was one that allows users to login via OpenID! This is really cool because it doesn’t require a user to actually register at your site and waste space! They can register at any website that offers OpenID such as Yahoo, WordPress, Flickr (also Yahoo) and many more!

I didn’t go with WP-OpenID because spammers can still register via OpenID and login on your site. They wouldn’t be spamming the registrations, that’s one plus side, but they are still encouraged to test out my comment filtering system..and they always jump at chances to piss people off like that. 😛

So I suggest you look into my “research” if you’re having similar trouble! Enjoy!

Vista: Repair with boot disk

vistaIf you ever experience problems with your Vista installation and it fails to boot, you’ll quickly learn that “fixmbr” is no longer used the same way (fixmbr is to be valid for Windows XP and several previous Windows platforms).

If you need to fix your then you may have trouble finding the remedy as I did. I searched for a little while not finding anything helpful. However, not that I’ve found it and had to use it a few times I am going to share it with you (and all just post it so I can reference it later more easily).

The recover steps are as follows:

  1. Power-on your system and immediately insert your installation disk.
  2. Press any key to boot your PC from the installion disk.
  3. Once booting has completed click “Next” after making sure that options such as language are appropriate for you.
  4. From the list of options provided, select repair. (This may take several minutes while the installation disk tries to find supported bootable partitions. Just be patient. 😉 )
  5. If the automatic scan does not detect your windows installation then you may have a lot of trouble regaining any information stored on your drive. If this is not the case for you then move on tot he next step. Otherwise, if this is the case then I suggest the following:
    • Obtain another hard drive, by purchase or borrow from a friend and install Windows on thenew hard drive.
    • Now install some freeware undelete software to recover your important files to the borrowed hard drive so you can use it later to move the files back to your system.
    • After recovering the files that you need to keep, format and reinstall Windows on your old hard drive.
    • Now you are ready to copy and paste the recovered files over.
  6. Now that the install disk has detected your old installation click next to continue.
  7. The next screen offers several things. Go a head and click to repair startup, but don’t count on this fixing anything (it has never fixed anything for me in the past, but it never hurts to try).
  8. Now click on the option to manually repair via the console.
  9. Once in the terminal/console, you will be using “bootrec“. Go a head and type “bootrec” without the quotes into the terminal and press enter to get an idea from the description that it provides for what it does. Now the commands that will fix your system are as follows (without quotes):
    • “bootrec -FixMbr” – this command will rewrite the contents of your master boot record since it is most likely corrupt, otherwise you probably wouldn’t be here.
    • “bootrec -FixBoot” – this command may not be necessary, but I use it just incase.
  10. Now that you have enter both of those commands to repair your boot process you just need to restart and see if everything is working again!

I’m not sure how you got into this situation in the first place, but if you have not been trying to install another operating system to dual boot along side Vista then you might want to look into the issue further. You can always use your best friend Google.com to find where other people have had similar problems and found solutions. I would suggest looking into this immediately to ensure that your data is not lost in future incidents. It might be that you have corruption in your hard drive and need to run checkdisk to repair any bad places. I hope this has been helpful to someone. If it has helped you at all, please let me know! Post a comment!

Installing Pidgin in Linux from Source

pidginAs many Linux users know by now, Gaim has been renamed for a second time to Pidgin due to legal issues with AOL over the use of ‘AIM’. Many distros of Linux operating systems still distribute the popular messenger client in older versions that are still under the title Gaim. I’m not the kind of person to use outdated software, so updating to Pidgin was one of the first things that I did when I made the move from Windows Vista to Ubuntu. I found the task to be a bit more lengthy than I had intended.

Most distros have communities that contribute packages that can install applications in a one step process by gathering all dependencies that are needed and installing them with the application. However, the great site that I’ve found for Debian packages seems to have a few packages lagging behind. I can’t have that. Who wants to install an older version of software than what is currently offered on the applications official site? Unfortunately there are no Debian packages available from Pidgin. That is not a problem! First things first:

  • Go to your Add or Remove application and completely remove anything associated with Gaim.
  • Open a terminal and install the following dev packages with the following commands (*The following terminal commands are for APT software package management systems. To use these commands with a different package manager you need to edit the syntax accordingly):
    • sudo apt-get install libglib2.0-dev
    • sudo apt-get install libxml2-dev
    • sudo aptitude install libnss-dev
    • sudo apt-get install libgtk2.0-dev
  • Go to www.Pidgin.im and download the source package.
  • Extract the source package and navigate to the folder that the files were extracted to in a terminal window.
  • You now need to configure and build Pidgin from the source files. Use the following commands in the terminal window to successfully configure Pidgin for your platform:
    • sudo ./configure
    • sudo make
    • sudo make install
  • Pidgin should now be successfully installed on your computer! You can now delete the source files that you downloaded from www.Pidgin.im.

If you experienced any problems while trying to follow this guide, please leave me a comment and I’ll try to help out. Always use Google.com to search for error messages before seeking help from others. Your questions are most likely already answered somewhere!