Jump to content

detected browser


fullyloaded

Recommended Posts

hi

i was wondering if anyone has any idea how to get this code to work for more then one browser? i can get it to work for one browser but have no luck on getting it to work for more then one browser thanks...

code that don't work:

<?php
include("browserDetection.php");
$user_browser = browser_detection('browser');

if ( $user_browser == 'mozilla' )
{
echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n");
}
else
{
echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n");
}
if ( browser_detection('msie') )
{
echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n");
}
else
{
echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n");
}
?>

code that works:

<?php
include("browserDetection.php");
$user_browser = browser_detection('browser');

if ( $user_browser == 'Mozilla' )
{
echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n");
}
else
{
echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/254263-detected-browser/
Share on other sites

hi here it is sorry

browser_detection code:

<?php
function browser_detection( $which_test ) {
$browser = '';
$dom_browser = '';
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
if (stristr($navigator_user_agent, "mozilla")) 
{
	$browser = 'mozilla';
	$dom_browser = true;
}
elseif (stristr($navigator_user_agent, "msie")) 
{
	$browser = 'msie'; 
	$dom_browser = true;
}
    elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari"))) 
{
	$browser = 'safari'; 
	$dom_browser = true;
}	
else 
{
	$dom_browser = false;
	$browser = false;
}
if ( $which_test == 'browser' )
{
	return $browser;
}
elseif ( $which_test == 'dom' )
{
	return $dom_browser;
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303834
Share on other sites

I believe he wants to display a different style sheet for each browser.

 

<?PHP
include("browserDetection.php");

//### Send the user agent to the function for it to return a correct value
$user_browser = browser_detection($_SERVER['HTTP_USER_AGENT']);

if ( $user_browser == 'mozilla' ) // If mozilla, show mozilla style sheet
{
echo("<link href='style-mozilla.css' type='text/css' rel='stylesheet'></link>\n");
}
else if ( $user_browser == 'msie' ) // If internet explorer, show ie style sheet
{
echo("<link href='style-ie.css' type='text/css' rel='stylesheet'></link>\n");
}
else // If another browser, show other style sheet
{
echo("<link href='style-other.css' type='text/css' rel='stylesheet'></link>\n");
}
?>

 

Regards, PaulRyan.

Link to comment
https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303856
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.