jim.davidson Posted October 8, 2007 Share Posted October 8, 2007 Is there a way to identify the brwser a visitor to my site is using? I would like to include site style based on the visitor's browser. If their us IE show layout one way, if their using Firefox show it another way...etc...etc. Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/ Share on other sites More sharing options...
trq Posted October 8, 2007 Share Posted October 8, 2007 Better off using Javascript for such taks though you can determine the browser type by looking at the $_SERVER['HTTP_USER_AGENT'] variable. Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/#findComment-364627 Share on other sites More sharing options...
TomKrush Posted October 8, 2007 Share Posted October 8, 2007 All you need to read the browser is the User Agent. PHP includes a method for Apache servers using the global $_SERVER. <?php $userAgent = $_SERVER["HTTP_USER_AGENT"]; //Parse out the browser from here ?> Edit: I didn't realize this but PHP also offers a function called get_broswer(); But it will only work with certain PHP configurations. <?php $browser = get_browser(null, true); print_r($browser); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/#findComment-364631 Share on other sites More sharing options...
jim.davidson Posted October 8, 2007 Author Share Posted October 8, 2007 I'm confused..I just tested that and it says I'm running Mozilla but I'm testing in IE Here's the code and the result <?php $userAgent = $_SERVER["HTTP_USER_AGENT"]; echo $userAgent; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> </body> </html> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727) Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/#findComment-364644 Share on other sites More sharing options...
TomKrush Posted October 8, 2007 Share Posted October 8, 2007 Im running Safari got Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1 But the code is gathering accurate data. It reads that Im using webkit and everything. But it does mention Mozilla. Here's yours Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727) Yours Says that your using Internet Explorer 6 (upgrade to firefox!! lol) and your on Windows XP. So I'd imagine I just described your machine. Hopefully someone with better Knowledge can explain why there's Mozilla in the front of the User Agent. Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/#findComment-364651 Share on other sites More sharing options...
jim.davidson Posted October 8, 2007 Author Share Posted October 8, 2007 OK, Now I see, I saw Mozilla at the beginning and did'nt look further. I have firefox, and IE and switch back and forth. Thanks for shinning the light for me. Quote Link to comment https://forums.phpfreaks.com/topic/72315-identifying-browser/#findComment-364664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.