LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2005, 12:50 AM   #1
apt
Member
 
Registered: Dec 2004
Posts: 34

Rep: Reputation: 15
Getting OS name using PHP


Hi
How can i get OS name in which PHP was installed using php?
And in LinuxOS i need to get the exact flavour name like Red Hat/Mandrake/Fedora/Debian. Is there any functions in php to retrive this ?

Any help would be appreciated.
 
Old 04-09-2005, 02:56 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I would use standard system commands
PHP Code:

$os 
= `uname -o`;

if( (
$pos strpos($os"Linux")) !== false) {
    if(
file_exists("/etc/slackware-version")) {
        
$distribution "Slackware";
        
$version file_get_contents("/etc/slackware-version");
    } elseif(
file_exists("/etc/redhat-release")) {
        
$distribution "RedHat";
        
$version file_get_contents("/etc/redhat-release");
    } elseif(
file_exists("/etc/SuSE-release")) {
        
$distribution "SuSE";
        
$version file_get_contents("/etc/SuSE-release");
    }
}

echo 
"Operating System : $os\n";
if(isset(
$distribution)) {
    echo 
"Distribution: $distribution\n";
}
if(isset(
$version)) {
    echo 
"Version: $version\n";


Last edited by keefaz; 04-09-2005 at 03:06 AM.
 
Old 04-09-2005, 03:56 AM   #3
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks for the reply, I will try it and let u know the result.
 
Old 04-09-2005, 05:57 AM   #4
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
hi
this worked fine
I used
this
$os = PHP_OS;
instead of
$os = `uname -o`;
And it worked in both the windows and linux.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 11:05 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
Updating php 4.3.1 from tar and keeping current php configuration with mandrake 9.1 mrjeep Linux - General 0 04-02-2003 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration