Andrew Gatenby

Get a Visitors’ IP Address - Accurately!

One of the sites that I’m working on at the moment requires some IP-specific functionality, but in testing I realised that the standard $_SERVER['REMOTE_ADDR'] wasn’t being as accurate as I wanted.  Then I realised that this variable doesn’t take into consideration visitors accessing via a proxy server or any random proxy/caching stuff put in place by their ISP.

So, I put together this simple little function that returns the actual IP of any visitor… Read the rest of this entry »

Increase max_connections in MySQL

This is a really quick “howto” guide based on experience in the office, where we had pages and queries that were unable to run properly, purely because of the number of queries that we were trying to pass to MySQL at once.

Read the rest of this entry »

10 Things you can do with Robots.txt for SEO

Robots.txt is a very useful and underutilised tool that allows web designers to control how their site handles spiders from search engines. The majority of search engine spiders take robots.txt and will parse the instructions prior to indexing a website.

Using robots.txt you can ensure that spiders only index certain parts of your website, and you can further specify as to which spiders are allowed to do so, and what pages they index.

Read the rest of this entry »

Prevent Image Hotlinking via .htaccess

Hotlinking to images on another domain is something that is frowned upon. Leeching other peoples bandwidth isn’t a polite thing to do, so if you find someone hotlinking images from your site, what can you do?

Well, you can edit your .htaccess file and have a little fun with them!

Read the rest of this entry »

How to List Files in a Directory

I put this block of code together for some freelance work I’ve recently completed, where the client needed to be able to have dynamic control of content and assign these pieces of content to various files in the website. The easiest way to do this, especially for future expansion, was to use the following code to generate a list of all files in the directory.

Read the rest of this entry »

Automatically Bounce non-www Domain to www. Domain (Canonical Domain Names)

You may have noticed, you may not, but when you go to www.andrewgatenby.com your browser is automatically bounce to andrewgatenby.com - no “www.” in the domain name. This is something I’ve actively done is to include what is called a canonical domain redirect. Basically, if you have a www.domainname.com then you can probably also visit your site by just going to domainname.com and it will still show the same content right?

Well, this to a search engine appears as 2 different domain names with the exact same content - something which could get you marked down in rankings. Using the modern-day witchcraft that is .htaccess we can solve this problem, and automatically bounce domainname.com to www.domainname.com by issuing a HTTP 301 (permanently moved) header redirect:

Read the rest of this entry »

Why do People Still use Older Web Browsers?

As someone who works with websites for a living, and then again until the small hours doing freelance bits, I have to say that I love the internet. It’s something that lets anybody can create a blog to share their thoughts, upload their holiday photos, or catch a sneaky episode of South Park on YouTube.

It may be a bit presumptuous to say at this point - but I’ve every faith that you enjoy using the internet too. Am I right?

People make sure they have all the necessary plugins like Flash, Quicktime and possibly even Java so they can see clips of cats dancing on YouTube, listen to your friends band on Myspace and catching up on the latest news.

So why do people insist on using an outdated web browser?

Read the rest of this entry »

Single Quotes and Double Quotes in PHP

PHP lets developers output strings to the screen using single or double quotation:

print ‘Hello world’;
print “Hello world”;

Both of these statements product the exact same output to the screen in terms of what the browser sees. However, these is a distinct difference in how PHP handles these statements.

Read the rest of this entry »