KaoriYui
KaoriYui

Reputation: 912

Detecting a users web browser using PHP and ask to open it with

I am able to detect the users web browser using below function

function get_browser_name($user_agent)
{
    if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
    elseif (strpos($user_agent, 'Edge')) return 'Edge';
    elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
    elseif (strpos($user_agent, 'Safari')) return 'Safari';
    elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
    elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';

    return 'Other';
}

To use it

$machine =  get_browser_name($_SERVER['HTTP_USER_AGENT']);

if($machine == "Internet Explorer"){

 echo "<script>

   alert('Your currently using Internet Explorer to view this page, some content will not show properly, Please use Firefox or Google Chrome.');

 </script>";

}else{

 echo "";

}

Now my next step is if lets say if firefox or Chrome is installed on the users machine script will prompt alert that asking "Do you want to open this site using firefox?", just want to know if PHP or javascript is capable on detecting if a application is installed on users machine.

Upvotes: 0

Views: 40

Answers (1)

Hurricane Development
Hurricane Development

Reputation: 2464

PHP is run server side and thus cannot detect a user's installed applications.

Although JavaScript is run client-side, it also cannot, unfortunately, detect applications.

Upvotes: 2

Related Questions