Determine if operating system is Mac
php, user-agent
Solution
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;
}
Problem
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"; } ```