Friday, July 10, 2009

How to find browser in PHP

How to find browser in PHP

This function gives you browser which the user currently using ….

Call this function with out parameter inside your php and assign this to any variable to get the browser which your using

//$variable_name = get_user_browser();

//echo “the browser you are using is=”.$variable_name;

The out is “the browser you are using is= firefox //if your are working in firefox

You can change the echo state in function according to your need

function get_user_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;

}

No comments: