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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.