Adding specific code for production only

Dec 26 2008 Published by Eneko Alonso under uncategorized

When you are developing a website you want to get as close as production as possible, to guarantee the final result will be appropriate and to make sure everything is going to work fine. But there are special cases when you want to add some code only on production, like stats code for example.

One easy way to do this is to check the server HTTP variables, the HTTP_HOST to be exact. This will contain your server host name, without the “http://” and the page URL. In my case, the value is “dev.enekoalonso.com”.

In PHP:

  1. <?php if ($_SERVER['HTTP_HOST'] == 'dev.enekoalonso.com'): ?>
  2. [Google Analytics code here]
  3. <?php endif; ?>

That way I don’t mess up my stats while spending hours creating a demo in my development environment.

2 responses so far

Setting up a development environment

Nov 29 2008 Published by Eneko Alonso under uncategorized

I want to left behind the days when I was developing code without any version control system. I have been using these at work for years now, but never for my personal projects. So know I use/have two SVN repositories:

But SVN doesn’t solve all problems, specially when working with Javascript and HTML. This is because I want to see my code in action. For this, I have http://code.enekoalonso.com. Until now I was uploading manually javascript and html demo pages that I was working on, but synchronizing it with the SVN repository became a pain very fast. So in order to avoid this, I have done a checkout of my SVN repository on my webserver. Now, whenever I update or add a new project to the repository, updating http://code.enekoalonso.com will be as simple as running the command:

svn update

And that’s it!

Now I can develop and test locally on my own computer, then commit to svn and update my code server without any pain.

No responses yet