Dont get caught by differing super globals in PHP

Recently I discovered that scripts I had written on my Mac would not run on our Linux servers. It wasn’t until I had a good look at the contents of the $_SERVER super global that I noticed a few anomalies with the contents of mine compared with others that I have been used to for so long…

Here is the main difference between mine and Mikes $_SERVER super global.

PHP 5.2.9 on Fedora 10 (Mikes dev machine)
["REQUEST_URI"]=> string(9) “/test.php”

PHP 5.3.0 on Mac OS X (10.6)
["REQUEST_URI"]=> string(28) “http://fliquid.dev/blog.html”

As you can see, the changes are sufficient to cause a lot of problems to a lot of scripts. Writing a regex to match either your REQUEST_URI (in this example) would fail on a script I write when it goes live and also any script that Mike writes that I run.

To get around this, we will likely write a small ‘compat’ (compatibility) library for detecting which style of super global is being used and append specific changes to each one so we only need to write one version of the code.

This is just a little ‘heads up’ to reduce the amount of hair pulling that can occur when scripts are pushed to a nix production environment after being developed on a Mac.

  • Johansmith

    Please tell me more about advanced concepts of PHP. I want some more.

    web application development

  • This is what I've been looking for. Thank you!

  • Imraan Afridi

    This shows that how to use the PHP in a proper manner and i learned a lot from here App development in chennai

  • Hey great tags. i would like to read more about the topic. thanks for sharing.

  • thanx for sharing the important tag. i want to read more php tags and articles if you write then i would like to read all. thanx for it.

blog comments powered by Disqus