Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to detect web browser of user using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 390
    Comment on it

    Hello Reader! If you are developing the website which depends on user's web browser then you must first find out the web browser that is opened. By using PHP you can get easily this info using the library code below:-

    <?php
    function detect_web_browser()
    {
        $u_agent = $_SERVER['HTTP_USER_AGENT'];
        $ub = '';
        if(preg_match('/MSIE/i',$u_agent))
        {
            $ub = "ie";
        }
        elseif(preg_match('/Firefox/i',$u_agent))
        {
            $ub = "firefox";
        }
        elseif(preg_match('/Safari/i',$u_agent))
        {
            $ub = "safari";
        }
        elseif(preg_match('/Chrome/i',$u_agent))
        {
            $ub = "chrome";
        }
        elseif(preg_match('/Flock/i',$u_agent))
        {
            $ub = "flock";
        }
        elseif(preg_match('/Opera/i',$u_agent))
        {
            $ub = "opera";
        }
    
        return $ub;
    }
    ?>
    

    Output:-

    $user_browser = detect_web_browser();
    if($user_browser == "Firefox"){
        //Now code for firefox
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: