Jump to content

Problem In Styling


SandySynaptik
 Share

Recommended Posts

I have a PHP script something like this:

<?phpif (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) {    echo 'Firefox';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {    echo 'Google Chrome';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Iron') !== FALSE) {    echo 'SRWare Iron';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Presto') !== FALSE) {    echo 'Opera';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {    echo 'Apple Safari';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {    echo 'Internet Explorer';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'ChromePlus') !== FALSE) {    echo 'ChromePlus';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'SeaMonkey') !== FALSE) {    echo 'SeaMonkey';}else {    echo '[Sorry, I can\'t recognise your browser, most probably because you might be on mobile device]';}?>

Now I want it to store it (browser's name) in a variable so that I can echo it on appropriate place.

Edited by Sandy Synaptik
  • Like 1
Link to comment
Share on other sites

You can try something like this(If it's what you mean):

<?php$browser;$noRec;if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) {   $browser = 'Firefox';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {	$browser= 'Google Chrome';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Iron') !== FALSE) {   $browser= 'SRWare Iron';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Presto') !== FALSE) {	$browser = 'Opera';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {	$browser = 'Apple Safari';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {	$browser = 'Internet Explorer';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'ChromePlus') !== FALSE) {	$browser = 'ChromePlus';}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'SeaMonkey') !== FALSE) {   $browser = 'SeaMonkey';}else {	$noRec = '[Sorry, I can\'t recognise your browser, most probably because you might be on mobile device]';}if(!empty($browser)){echo $browser;}else{echo $noRec;}?>

Within that particular page, you'll be able to echo out $browser anywhere. If you want to carry it to other pages, you can store in $_SESSION['browser'] = $browser; Edit: Correction of the word 'browser'.

Edited by Don E
Link to comment
Share on other sites

Since strpos returns a number or FALSE, check to see if a number is returned, if it does, it means its true, if not, it means false: So try making 'if' statements like this:

if (is_int(strpos($user_Agent, 'Chrome')))

OR simply:

if (strpos($user_Agent, 'Chrome')) {

... where $user_Agent is the browser of the visitor. Have this at the top of the page:

$user_Agent = $_SERVER['HTTP_USER_AGENT'];

Edited by Don E
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...