Jump to content

Problem In Styling


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

I am using something like this for echoing:

<ul><?phpecho '<li><strong>Browser:</strong> <span>'.$browser.'</span></li>';?></ul>

But getting an error about Notice: Undefined variable: browser in...

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

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...