Jump to content

Problem In Styling


SandySynaptik

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.

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'.

Link to comment
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 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'];

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...