Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if operating system is Mac

Tags:

php

user-agent

I have been doing a lot of Googling recently to try and find a simple, easy php script that will identify if the user is on a Mac or not.

I want to use this to tell users if the keyboard shortcut I am telling them is "control" or "command". I don't need to know the browser or anything, just if the computer is a Mac.

Here is an outline of what I'm asking is possible:

if (operating_system == Mac)
{
    echo "command";
}
else
{
    echo "control";
}
like image 452
totallyuneekname Avatar asked Apr 06 '13 01:04

totallyuneekname


People also ask

Is my computer x64 or x86 Mac?

Apple macOS Select the About This Mac option in the Apple menu. On the About This Mac window, click the More Info option. Open the Hardware section and find the Processor Name attribute. Once listed, perform an Internet search, using the CPU's processor name as a keyword, to determine if it's a 32-bit or 64-bit CPU.

What is the difference between macOS and OSX?

Is there any difference between Mac OS X and macOS? No, they are essentially the same thing — just named differently. In fact, three terms were used at different times with reference to Apple's operating system: Mac OS X, OS X, and macOS. Mac OS X was the official naming through version 10.7, from 2001 to 2011.

What is the current macOS 2022?

macOS Monterey will be succeeded by macOS Ventura, which was announced at WWDC 2022 on June 6, 2022. Apple Inc. High powered meets "Hi everyone." The operating system is named after Monterey Bay, continuing the trend of releases named after California locations since 2013's 10.9 Mavericks.


1 Answers

Create a page: identifier.php

<?php
$user_agent = getenv("HTTP_USER_AGENT");

if(strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
elseif(strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
?>

then include it on the header of your site.

After that you can use it like this:

<?php
if($os === "Windows")
{

}
elseif($os === "Mac")
{

} 
?>

Edit:

For windows phone:

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone os') > 0) {
    $mobile_browser = 1;
  }
like image 61
Fabio Cardoso Avatar answered Nov 16 '22 01:11

Fabio Cardoso