How reliable is server side detection of flash? - php

In answering a question on stack overflow, one person recommended using the following code to detect flash server-side, he pointed out that it does not work in safari:
if (strstr($_SERVER['HTTP_ACCEPT'], 'application/x-shockwave-flash')){
$hasFlash = true;}
Testing for Flash capability on the server-side
My question: why does it not work in safari, and how reliably does it work with other browsers?

That's because Safari decided not to send the HTTP_ACCEPT headers of every single possible "acceptable" request, including Flash. It will be highly unreliable to perform the test like this.
A better way of doing it could be to test on the client side using Javascript, set a cookie, then redirect.

All I could think of is that the mime type would not be detected properly by Safari. Safari might not recognize what application/x-shockwave-flash means. I tried to find similar stories in Google but unsuccessful.

Related

So the user agent can be faked.. Ok... is there a valid reason why I shouldn't use php to detect the browser?

I have never understood why some people say making custom css for each browser is a bad thing. To keep my page size down and download times fast it makes perfect sense to me to make a custom css for the major browsers (especially IE in its many different forms), and a general catch all css for everything else.
If you want to send out a bloated, huge, Swiss army knife of the css world, for all situations then go right ahead I'm not going to stop you.
Fast detection of the browser is important when doing this. Loading a JavaScript file to detect the browser seems slow. So I would prefer to use php to detect the browser, and send out the specified css. Or at least a general browser specific css then use the JavaScript to load a more detailed version of the css.
But I've read article after article about why this is a bad thing. The main reason behind each of these articles is because the user agent can be faked. Or there using Firefox but the server thinks they're using IE7 so it sends out the wrong css file.
As a developer/designer of web apps why is this my problem? If you want to use Firefox, but tell my server your using safari or IE*, and get a crappy looking page, why is it my problem?
And don't throw that whole if the user can't see your site right they'll never come back, or some kind of similar argument at me. a normal user isn't going to be doing this. its only going to be the people who know how to do this, and will know whats wrong when my site looks crappy.
This is similar to looking at my site on a old Apple II (I have no clue how), and yelling at me because everything looks green.
So is there a good reason, not a personal preference, why I shouldn't use php to detect the browser and send out customized css files?
I do this mostly for the different versions of IE. It just seems like for some sites, adding the if IE6 and if IE7 parts just double or triple the size of the css file.
Typically when a user intentionally fakes the user agent string, it is because something is not viewable in the user's browser that should be. For example, some sites may restrict users to IE or Firefox, but the user is using Iceweasel on Debian. Iceweasel is just a Firefox renamed for trademarked reasons (there are a few other changes also), so there is no reason that the site should not work.
Realize that this happens because of (bad) browser detection, not despite it. I would say you don't need to be terribly concerned about this issue. Further, if you can just make your site reasonably cross-browser compatible, it won't matter at all. If you really want to use browser-specific CSS, and you don't want to do so all in one CSS file, don't let a fake user agent stop you.
As long as the only thing you're doing is changing style sheets, there is no valid reason as far as I can tell. If you're attempting to deliver custom security measures by browser, then you'll have issues.
Not sure about php but in Rails it is normal and dead simple practice to provide css files and different layouts based on the user agent particularly when considering that your site is just as likely to be accessed by any of the myriad of available mobile devices, never mind writing for the most popular (Currently Firefox) browsers and even writing custom MIME types if need be is also dead simple.
IMO not doing so is pure laziness on the coders part but then not all sites are developed by professional teams of developers with styling gurus at hand. Also in languages other than Rails it might not be so simple. Sorry, I haven't a clue about PHP so this may not be an appropriate reply
In my opinion, starting with normalize.css, and having a base style sheet to start, overriding the base styles as needed usually works along with making sure you set appropriate fallbacks. If you really need it a few media queries, and feature detection can go a long way.
One reason you shouldn't base things off of the browser is because major search engines like Google and Yahoo prohibit displaying different content for different browsers. GoogleBot can detect different CSS and HTML and you may get bad search positioning. Additionally, if you use any advertising services you may be in breach of their contract by displaying varying content.

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");
}
});

document.referrer - limitations?

I am unable to get a lot of referral URLS using document.referrer. I'm not sure what is going on. I would appreciate it if anyone had any info on its limitations (like which browser does not support what) etc.
Is there something else i could use (in a different language perhaps) that covers more browsers etc?
I wouldn't put any faith in document.referrer in your Javascript code. The value is sent in client side request headers (Referer) and as such it can be spoofed and manipulated.
For more info see my answer to this question about the server side HTTP_REFERER server variable:
How reliable is HTTP_REFERER
Which browser are you looking in? If the referring website is sending the traffic via window.open('some link') instead of a regular <a> tag, then IE will not see a referrer. It thinks it's a new request at that point, similar to you simply going to a URL directly (in which case there is no referrer). Firefox and Chrome do not have the same issue.
This is NOT just a javascript limitation, HTTP_REFERRER will NOT work either in this specific scenario.
Just to make sure you're on the same page, you do know that if someone types a URL directly in their web browser, the document.referrer property is empty, right? That being said, you might be interested in a JavScript method to get all HTTP headers. If you prefer PHP (since you're using that tag), the standard $_SERVER variable will provide what information is available. Note that the information is only as reliable as the reporting web browser and server, as noted by Kev.
The document.referrer will be an empty string if:
You access the site directly, by entering the URL;
You access the site by clicking on a bookmark;
The source link contains rel="noreferrer";
The source is a local file;
Check out https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer

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.

PHP upload file using PUT instead of POST

I read something about this on PHP docs, but it's not clear to me:
Do the most widely used browsers (IE, FF, Chrome, Safari, Opera, ...) support this PUT method to upload files?
What HTML should I write to make the browser call the server via a PUT request? I mean do I need to write a FORM with an INPUT file field and just replace the attribute method="POST"with method="PUT"?
On the PHP docs (link above) they say a PUT request is much simpler than a POST request when uploading file, along with this advantage, what other advantages/disadvanatges do the PUT has got compared to the POST?
The PUT method cannot be used from a <form>. MSIE does not support it through the user GUI at all.
You can however use XMLHttpRequest. It seems to be defined in the standard and WHATWG / HTML5. My browser (Opera) obviously likes it.
http://old.mnot.net/javascript/xmlhttprequest/
IE might work too, as a short Google search suggests. And Firefox looks fine. Not checked Chrome or Webkit.
Server-site you need a specially designated script to handle an incoming PUT request. Look into the Apache docs. A mod_rewrite rule might usually do.
The genral adavantage of PUT is that there is no file encoding / marshalling into a multipart/* mime type required. In theory this allows uploading larger files more reliably. Allthough if you use PHP, it won't help you much. It's meant for Webservers with WebDAV support and/or direct filesystem write access. (Apache can save uploaded files itself, if you use that.)
I think the method is supported by most major browsers, but you can't account for every browser and other client that is out there. From a cursory look at the user contributed notes, this sometimes even needs server-side configuration to work.
Also, handling any additional form values you may want to send along with your file becomes more difficult.
I wouldn't use it. Way too much possible hassle for little actual gain.
The fact that PUT is rarely used for the purpose and only supported by major browsers excludes it from the any possible use here.
PUT is not very widely supported by browsers, and isn't generally used for interactive HTML forms.

Categories