Block IE and Opera using PHP - php

I want to redirect user to a selected page if they use Any Version of IE or Opera. Because my website is using CSS 3 fully with different effects (animation effects) which are not supported by IE and Opera yet.
I want to do it using PHP. Should the code bellow work?
if(preg_match('/MSIE/i',$u_agent) || preg_match('/Opera/i',$u_agent))
{
header("Location: http://www.example.com/reject.html");
}
Or suggest me a better way please...

Use this
if(preg_match('/MSIE|Opera/i',$u_agent))
{
header("Location: http://www.example.com/reject.html");
}

Unfortunately there is no way to do this only with PHP. Browsers usually send a user agent string, but this can be spoofed quite easily. There is no way to be 100% sure of the browser the user is using, however the most reliable way to tell is with JavaScript. You can either write your own or do a quick Google search and find a premade one.

Related

Using PHP to determine a user can handle FancyZoom (Javascript image zoomer)

I'm working on a small PHP-driven website that's so basic that I can't imagine a browser from any time in the 2000's, if not further back, would have any serious issues with it.
I added the FancyZoom Javascript image viewer, though, and it's the ONE part of my site that I can't bet my life on in terms of across-the-board compatibility, especially taking fragmented mobile browsers into account (for instance, I'm still using an iPhone 3GS, so I know luddites like me are out there).
I know browser/feature detection is discussed here often, but I've got a relatively specific request since I'm not an up-to-date web programmer. What specific features (or user agents, if the case may be) should I be detecting to determine whether to enable an image viewer like FancyZoom or simply leave the user with a direct image link?
I'd imagine that it should be possible to filter out a few cases where the image loader wouldn't work, without going so far as to use one of those uber-complex user agent parsers that require updates, etc. This is a really simple, specific detection problem.
Any ideas on how to boil this down to the simplest possible features to check for would be great. Thanks!
you could do something like this to weed out old browsers
$browser = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(?i)MSIE [1-6]/',$browser) && !preg_match('/Opera/i',$browser))
{
$image = 'Non fancy zoom';
} else
{
$image = 'fancy zoom';
}
I have not messed with the jquery plugin your using, so I do not know what browsers it is good for etc, but you can use the below to find their browser and just write rules...
$browser = $_SERVER['HTTP_USER_AGENT'];

How to detect browser? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I detect the browser with PHP or JavaScript?
I need to show different information in different browser ( Internet Explorer, Firefox, Chrome, Safari and Opera ). So I need a way to detect the user's browser.
What is the best way to do that in my case ?
I could use PHP or Javascript but I want to avoid to use external library like jQuery.
Thanks :)
Browser detection is a really unreliable practice, and should be avoided. That being said, you typically get started by sniffing navigator.userAgent in JavaScript, or checking the userAgent (or get_browser()) as it comes across with the requests to your server.
However, don't do this - please (for the ponies). Use feature detection instead. Tools like Modernizr make it very easy for you to deliver content up only when it's supported, and to code around differences between browsers.
you can use the following:
php
$agent = $_SERVER["HTTP_USER_AGENT"];
if (preg_match("/MSIE/i",$agent)) { echo "its ie!"; }
javascript
navigator.appName
navigator.appVersion
you can combine/crosscheck and starting to make a large if/else chunk
with everything you find.
also check here
but i agree, this is non 100% reliable

Conditional PHP for IE to direct to different site?

I am pretty new to php so bear with me :)
I am trying to create a web page that can use the get_user_browser function in php to then direct the user to a separate HTML page.
My website is http://www.danabohne.com and I just realized it is barely visible in IE. Unless there's a different way to go around this I want to make a separate static HTML site that can be seen by IE users.
Any feedback would be extremely helpful!
<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
if( strpos($useragent,"MSIE 6.0") ) {
header("Location: http://google.com");
}
?>
You can add more if conditions as needed.
However , Like John mentioned in the comments. I would advise you to create a separate stylesheet and create a fallback design rather than redirecting to another page.
Firstly, it's important to note that browser detection on the server is not recommended, because it is possible for browsers to provide false user agent details, or none at all. (I know of some firewall products that routinely strip out this kind of data from the http headers).
Secondly, the get_user_browser function only works if you have a valid browsecap.ini file. If you're having trouble getting the function to work, check that you have this ini file and that it is up-to-date. (also note that you will need to keep it updated whenever new browsers or browser versions are released).
Finally, most (virtually all) IE-specific display issues can be resolved without having to create a separate page for IE.
Specifically in your case, I can see what the problem is straight away when looking at the HTML source code for your page:
The problem is the <pre></pre> that is in the first line of your code immediately before the <!DOCTYPE>. I assume this is the left-overs from some debugging code that hasn't been removed properly.
This <pre></pre> is going to cause IE to fall into "quirks mode", because IE sees the <pre> and assumes it doesn't have a doctype. Without a doctype, IE assumes the page should be in quirks mode.
Quirks mode makes IE's rendering engine display the page completely differently (it's basically an IE5-backward-compatibility mode), so it's no wonder your page looks rubbish in IE.
This behaviour is the same in all versions of IE.
If you have other IE-specific problems, it would be better to try to fix them on the page, as there are a lot of tools and hacks available to make IE work better.
Hope that helps.

How to send webkit user agents to one site version and all the rest to another?

I am a humble graphic designer who is trying his best to learn development. I have a challenging question that I need some very clear and straightforward help with. From my research it seems that my solution can be accomplished with PHP or Javascript. I am totally an infant in both languages but I don't care which one is used. Preferably whatever is easiest for a noob like me.
So her is the deal…
I have a site I have just put together with a bunch of nice -webkit-transforms http://www.eameswords.com I want to send desktop Safari/Chrome to this site. I want to send iPad and iPhone to a separate touch enabled version too.
The kicker…
I have an Adobe flash version of the site as well. It does all the same interactivity. I want to send user agents for IE, Firefox and Opera to this version.
So I have 3 versions of my site!!
I would like to put all three versions of my site in three separate folders for organizational purposes.
So I need three types of user agent detection and three redirects:
iPad & iPhone (mobile Safari) ––––> folder01
Webkit Browsers (Safari/Chrome) ———> folder02
All other browsers (IE, Firefox, etc.) ————> folder03
This is crazy but I need some serious help to make this work. If anyone can give me a straightforward answer I would be happy to swap any of my design skills to pay-it-back. I say this because I need someone to literally write out the solution so I can process it, learn from it. I am really bad at piecing code together.
Thank you so much in advance!!!
Check the user-agent header for the signature.
For example, in PHP:
$user_agent = $_SERVER["HTTP_USER_AGENT"];
//Condition checks: Does $user_agent equal the signature of a webkit browser?
//If not, redirect: header("Location: main.php?nonwebkit=true");
Search for the existence of "webkit" in the User agent string. If it exists, fine. Otherwise, redirect the user to the flash page.
jquery solution:
$(document).ready(function() {
if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)){
window.location.replace("URL1");
}
else if ($.browser.webkit){
window.location.replace("URL2");
}
else{
window.location.replace("URL3");
}
});

How to detect browser addons in Firefox, Opera and IE?

How to - using either JavaScript or PHP - detect addons that are used by a user? In particular the ORBIT addon.
I realize this is an old question but it popped up on a google search for me. It most definitely is possible to detect browser addons. Here are a couple of resources to check out:
http://ha.ckers.org/blog/20060823/detecting-firefox-extentions/
http://webdevwonders.com/detecting-firefox-add-ons/
In general, you can't.
Some addons (eg, Firebug) expose a client-side object model to the page, in which case you can detect them using Javascript.

Categories