Home Tutorials Libraries Scripts Jobs PHP+MYSQL E-Book Contact Us

PHP Detecting the Host Platform

Feb 09, 2010 Author: strumica

Now let's look at how PHP interacts with the web server's host environment.

Detecting the Host Platform
Because different types of systems have different sets of host commands available, if you are writing a script that could potentially be executed on different platforms, it's useful to detect what kind of web server is being used.

The constant PHP_OS contains a string that represents the operating system. The most common reason for checking this is to find out whether a script is running on a Windows platformafter all, most Unix-like systems, and even Mac OS, behave in a very similar way.

The value of PHP_OS on a Windows web server could be Windows, WINNT, or WIN32, and in the future, other values may come into existence. Therefore, to test for a Windows platform, you should perform a non-case-sensitive comparison on the first three characters of the string. The following condition shows just one of the ways you can do this:

if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { 
 ...
}

Darwin Be cautious to check only that the value of PHP_OS begins with WIN, as modern versions of Mac OS report themselves as Darwin.


views 564 Bookmark and Share
Lunarpages.com Web Hosting hostgator
Subscribe to our Rss Feed Follow us on Twitter Become our Facebook fan
Most Viewst
Articles
Nov 24, 2008 Wordpress
Nov 24, 2008 Joomla CMS
Sep 30, 2009 How many visitors browsing the site at the moment?
Nov 21, 2008 Anti Spam Bot Email by ASCII
Nov 24, 2008 Dynamic copyright year with php
Recent
Comments
Nov 24, 2008 Wordpress
Nov 24, 2008 Joomla CMS
Sep 30, 2009 How many visitors browsing the site at the moment?
Nov 21, 2008 Anti Spam Bot Email by ASCII
Nov 24, 2008 Dynamic copyright year with php