Jump to content

[SOLVED] PHP Browser Check


mattal999

Recommended Posts

Hi,

 

I have this:

 

<?php

$browser=strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($browser, 'msie')) {
?>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php
} else if(strpos($browser, 'chrome')) {
?>
<link rel="stylesheet" type="text/css" href="css/stylechrome.css" />
<?php
} else if(strpos($browser, 'firefox')) {
?>
<link rel="stylesheet" type="text/css" href="css/styleff.css" />
<?php
} else if(strpos($browser, 'opera')) {
?>
<link rel="stylesheet" type="text/css" href="css/styleopera.css" />
<?php
} else {
?>
<link rel="stylesheet" type="text/css" href="css/styleff.css" />
<?php
}

?>

 

And i have checked Opera's output of $browser, which is: opera/9.51 (windows nt 5.1; u; en)

 

However, it doesn't detect the word opera in that phrase!!! Help!

Link to comment
https://forums.phpfreaks.com/topic/123970-solved-php-browser-check/
Share on other sites

yeah it is working fine with the browser's

there must be a little problem i dont have opera

so its quite difficult to try thsi problem

 

but change anyother php funtion

other then this strpos because

function in php are not 100% successfully

running every time there are many problems

in fucntion some time it works sometimes not,.

 

so i suggest you to change or use any other one

 

thanks and regards

yeah it is working fine with the browser's

there must be a little problem i dont have opera

so its quite difficult to try thsi problem

 

but change anyother php funtion

other then this strpos because

function in php are not 100% successfully

running every time there are many problems

in fucntion some time it works sometimes not,.

 

so i suggest you to change or use any other one

 

thanks and regards

 

...What?

 

Also, your problem is that you're not using strpos() correctly.  strpos() returns the position of the found string, correct?  If it finds the string at position 0 in your big string, it returns 0.  If used as you have it set up, this evaluates to FALSE and then doesn't activate the if.  You need to do:

 

if (strpos($browser, 'opera') !== false) {

 

}

 

That should be done for ALL of them, and any other time you use strpos, btw.

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.