SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: Determine Operating System
-
Oct 23, 2007, 15:33 #1
- Join Date
- Jul 2006
- Location
- Ontario, Canada
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Determine Operating System
Hi,
I'm trying to determine the operating system that my script is running on (for portability concerns). phpinfo() shows the correct information under Environment > OS. The php documentation suggests that this information can be found in $_ENV['OS']. However, var_dump() displays this as NULL. var_dump($_SERVER['OS']) also returns NULL. In fact, var_dump($_ENV) is NULL as well.
How can I determine the operating system that my script is running on?
Thanks!
-
Oct 23, 2007, 15:58 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
finding the OS
Try
PHP Code:<?php
echo php_uname('s');/* Operating system name */
echo "<br />";
echo php_uname('n');/* Host name */
echo "<br />";
echo php_uname('r');/* Release name */
echo "<br />";
echo php_uname('v');/* Version information */
echo "<br />";
echo php_uname('m');/* Machine type */
echo "<br />";
echo PHP_OS;/* constant will contain the operating system PHP was built on */
?>Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Oct 23, 2007, 16:13 #3
- Join Date
- Jul 2006
- Location
- Ontario, Canada
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, it works great!
-
Oct 23, 2007, 17:23 #4
Umm did you try print PHP_OS;
http://www.php.net/php_uname
-
Oct 23, 2007, 17:45 #5
- Join Date
- Jul 2006
- Location
- Ontario, Canada
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The page you linked says that PHP_OS refers to the operating system that PHP was built on. I need the OS it is running on. For that, it appears that php_uname('s') is correct.
-
Oct 23, 2007, 18:05 #6
No that is wrong PHP_OS = The OS PHP is running on. I don't know why to documentation says that when it isn't. In either case it will match the OS PHP is running on and built on.
-
Oct 23, 2007, 18:51 #7
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
operating system
On my shared server both php_uname('s') and PHP_OS give Linux
But on my localhost php_uname('s') gives Windows 9x (yes, I still have Windows 98) and PHP_OS gives WIN32
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Oct 23, 2007, 19:18 #8
Perhapes a better name for it should have been PHP_PLATFORM as it mainly returns that.
Pre NT windows will return WIN32 and Windows NT (2000, XP, Vista) will return WINNT.
Easy enough to know the OS that PHP is running on from it.
-
Oct 23, 2007, 20:23 #9
- Join Date
- Apr 2005
- Posts
- 287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 24, 2007, 01:26 #10
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 24, 2007, 03:20 #11
But as I see it Windows is really the only OS that you have to look at for as it has the most differences like path separators and uses .dll for extensions instead of .so.
So far mostly everything I see works in everything or everything but windows so never needed anything else but PHP_OS.
Mmmm well its understandable.
-
Oct 24, 2007, 03:33 #12
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sure it is, on the other side, I don't think the lack of personal experience with cross-platform issues is a valid reason to make highly debatable statements like the one I quoted.
Bookmarks