nashsaint Posted May 20, 2008 Share Posted May 20, 2008 Hi, Is there anyway to set my php page to strictly viewable only on firefox? Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/ Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 what do you mean by "strictly viewable only" also you could check the clients browsers Agent in the $_SERVER super global Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/#findComment-545511 Share on other sites More sharing options...
thebadbad Posted May 20, 2008 Share Posted May 20, 2008 A simple way would be to put this at the top of your code: <?php if (!strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {echo 'Viewable with Firefox only!'; exit;} ?> But remember that tech savvy users can alter the user agent string to anything they want, so it will not keep those from seeing your page in other browsers. It should stop most people though. Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/#findComment-545522 Share on other sites More sharing options...
Jpoel Posted May 20, 2008 Share Posted May 20, 2008 Use something like this? <?php $useragent = $_SERVER['HTTP_USER_AGENT']; if(!preg_match('|Firefox/([0-9\.]+)|',$useragent,$matched)) { die("You must use firefox to view this page"); } //Anything from now on will only be seen by firefox users. ?> Edit: Sorry, didnt see your post BadBad Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/#findComment-545523 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 while thebadbad & Jpoel code will work (i prefer thebadbad code, sorry Jpoel preg_match overhead), you must keep inmind, Only around 39% of users are using firefox (its increasing, this time last year is was around 33%) Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/#findComment-545528 Share on other sites More sharing options...
thebadbad Posted May 20, 2008 Share Posted May 20, 2008 When I code (XHTML/CSS) I go for compatibility in Firefox and IE7. They're handling the code mostly the same (the IE team sure has improved with IE7, although there's still some CSS issues around). I know there's still a large group of IE6 users, but they're hopefully updating sooner or later. My point is, along the lines of MadTechie's, that you shouldn't cut off all non-Firefox users, but try to keep up with the standards, and make your code work in at least IE7 and Firefox. But maybe you just wanted to play around with browser specific code. If so, fine, but my advice still applies Quote Link to comment https://forums.phpfreaks.com/topic/106423-firefox-only/#findComment-545537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.