SandySynaptik Posted October 26, 2011 Share Posted October 26, 2011 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 More sharing options...
Don E Posted October 26, 2011 Share Posted October 26, 2011 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 More sharing options...
SandySynaptik Posted October 26, 2011 Author Share Posted October 26, 2011 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 More sharing options...
Don E Posted October 26, 2011 Share Posted October 26, 2011 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 More sharing options...
SandySynaptik Posted October 26, 2011 Author Share Posted October 26, 2011 The problem still exists. See the attachment.send.php Link to comment Share on other sites More sharing options...
Don E Posted October 26, 2011 Share Posted October 26, 2011 Make sure $browser is spelled correctly everywhere. Look closer, you'll see it mis-typed.(broswer) Link to comment Share on other sites More sharing options...
SandySynaptik Posted October 26, 2011 Author Share Posted October 26, 2011 Problem is solved, what is HTTP_X_FORWARDED_FOR? Link to comment Share on other sites More sharing options...
Don E Posted October 26, 2011 Share Posted October 26, 2011 A http header for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balance. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.