We use the following function to auto detect if we are on a machine internally or on a live server and then choose the appropriate configs for various components:
Create and later look for a file that only exists on the live server's filesystem.
Granted, your environments should be as similar as possible; what I'm suggesting is something like this: in directory /var/environment/, have a file named {devel|test|qa|staging|live}, depending on the server you're on - then just check the filename.
Of course, you need to exclude this file from version control and from whatever build process you may have.