MyBB Community Forums

Full Version: detect the browser
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,
as you are aware various browsers render pages in different ways is there a way to detect the browser and set a theme that is optimized to the users browser ?
There is also the other point some times the same browser on different platforms gives different results ... so perhaps a way to platform check as well would be good
Ive code that myself a while ago too :>

I think this will help:

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
	{
		echo "You are not using Microsoft Internet Explorer!"
	}
	else
	{
		echo "You are using Microsoft Internet Explorer!"
	}
		return $page;

You can replace MSIE by different shortcuts for browsers.

Its a dirty code though, I am sure there is an easier code., I am not a gnius though
Depends... are you wanting to do it via PHP, JavaScript, or HTML? Toungue
(2011-10-15, 04:10 PM)Dylan M. Wrote: [ -> ]Depends... are you wanting to do it via PHP, JavaScript, or HTML? Toungue

The code needs to placed in either the header or header include in order to get the browser id then display the correct theme for the browser ... so ?I guess this could be in any format .. but looking at the header & header include code I would guess the same format as those 2 files would be correct ....
(2011-10-15, 04:03 PM)Tankey Wrote: [ -> ]Ive code that myself a while ago too :>

I think this will help:

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
	{
		echo "You are not using Microsoft Internet Explorer!"
	}
	else
	{
		echo "You are using Microsoft Internet Explorer!"
	}
		return $page;

You can replace MSIE by different shortcuts for browsers.

Its a dirty code though, I am sure there is an easier code., I am not a gnius though

thanks for that ,,, gives me a starter Lightbulb
(2011-10-15, 04:31 PM)JimR Wrote: [ -> ]The code needs to placed in either the header or header include in order to get the browser id then display the correct theme for the browser ... so ?I guess this could be in any format .. but looking at the header & header include code I would guess the same format as those 2 files would be correct ....

If you want it to change theme, you'll need the PHP version, and this would be best written as a plugin instead of as a core file edit. The other posted has given you a good lead on the PHP code to start with.
(2011-10-15, 06:08 PM)Dylan M. Wrote: [ -> ]
(2011-10-15, 04:31 PM)JimR Wrote: [ -> ]The code needs to placed in either the header or header include in order to get the browser id then display the correct theme for the browser ... so ?I guess this could be in any format .. but looking at the header & header include code I would guess the same format as those 2 files would be correct ....

If you want it to change theme, you'll need the PHP version, and this would be best written as a plugin instead of as a core file edit. The other posted has given you a good lead on the PHP code to start with.
from that I guess there is no 'user agent' variable with in mybb... the only reason for writing the code is to get around the problems with different browsers/OS. I'll read you on how to write a plugin and ask silly questions in the correct forum when it goes wrong Big Grin
Well, in theory the idea would be to provide a single theme that works across all browsers Smile
(2011-10-15, 07:20 PM)Dylan M. Wrote: [ -> ]Well, in theory the idea would be to provide a single theme that works across all browsers Smile

Have you tried working with IE8 and below ... no webkit support so all the nice rounded boxes become old hat square boxes which in turn can make the theme look nasty ! But IE9 renders the page nearly spot on from the design.
Then of course you have the different page rendering between opera (windoze) and opera (Linux) then you get differences between Google Chrome (windoze) and Chromium (Linux). Firefox (windoze & Linux) tend to give the same result with the exception of Line height To date I have not got a Mac but I would guess there will be differences there too !
The idea was to give all users something that renders well ...
I.E <=8 series browsers :- no boxes
Windows Firefox a different line height to Linux Firefox
slightly different colours between Google Chrome (windoze) & Chromium (Linux) as the 2 browsers appear to render colours slightly differently.
This makes my think that to do the job properly you would have to try to find a 'happy medium' to satisfy all browsers and perhaps a better approach would be to design the theme for the browser so the user gets the design you intended to display