echo – N77 Design | NickClaeboe.com https://www.nickclaeboe.com Atlanta Web, Graphic & Flyer Design • Design Portfolio & Rates for Nick Claeboe Custom Design Work Wed, 03 Mar 2021 14:10:24 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://www.nickclaeboe.com/wp-content/uploads/2016/05/favicon-60x60.png echo – N77 Design | NickClaeboe.com https://www.nickclaeboe.com 32 32 Get User Agent For Custom Browser Styles – PHP Get User Agent Variables https://www.nickclaeboe.com/2016/09/28/get-user-agent-custom-browser-styles-php-get-user-agent-variables/ Wed, 28 Sep 2016 11:36:29 +0000 http://www.nickclaeboe.com/?p=435

Often, I come across the need to pull the user agent from the browser to echo custom CSS styles for that specific browser. This comes in very handy when developing for mobile. Below is a list of the major user agent/browsers and the php call to get the user agent from the session.

Use the following code below to grad the user agent for you development needs.

/// get user agent for custom browser styles
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 'IE';

return 'Other';
}
?>

<style>
.IE #form form select {
width: 185px;
height: 26px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.IE input[type="text"]{
height:27px;
width: 185px;
margin-left: 8px;
/* margin-right: 8px; */
text-indent: 10px;
border: 1px solid #ccc;
}
.Firefox #form form select {
width: 159px !important;
height: 30px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.Chrome #form form select {
width: 190px;
height: 26px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.IE input::-ms-clear {
display:none;
}
</style>

<body class="<?php echo get_browser_name($_SERVER['HTTP_USER_AGENT']); ?>">

 

]]>