Php user-agent Graceful Degradation - php

I am looking to detect how modern the user's browser is. For example Google displays a table based gmail depending on the browser, and a table based layout for Google images also depending on the browser. http://mail.google.com/support/bin/answer.py?hl=en&answer=6557
Google's choice of "modern" browsers is fine with me, but I am unsure how to insure future functionality. When user agent strings change or a new browser is released it seems the list of user agent strings would have to change.
Edit : I ended up using the concept as the mordernizer php server library. I test for functionality and if the default settings aren't correct I set a cookie and refresh the page.

Check out the modernizr-server library, which is a port of Modernizr to php, for detecting what modern features a visitor's browser supports. More information is available in the Modernizr on the server-side blog post.
Browser.php is similar, but detects OS, browser, and version (not whether a particular feature is supported). The Browser Capabilities Project is another possible option.

Related

Can I target specific browsers/devices with the Manifest or Appcache file or just exclude the appcache from Desktop browsers?

Essentially I would like to be able to use an appcache file on my site but only for mobile devices, to enable those devices to view the website/webapp I am developing offline, however desktops/laptops often have access to the internet and I would rather these view the site as is, with no manifest/caching etc..
I am aware user agent sniffing is at best unreliable although can provide some good results, if this could be avoided it would be best.
The site/webapp I am developing is built in HTML/CSS/JS/PHP and uses responsive layouts to serve the same pages of the site to each device with customised views/layouts depending on the devices width (using css media queries).
Thanks for any help in advance, all my searches for this specifically have proved unfruitful :(
Update
After Robertc's comments below I would like to clarify that it is Desktop Browsers (ie the very same browsers that are used on laptops) that I would like to exclude any caching from via appcache/manifest file... This is a requirement from client and also from me as programmatically it seems easier to target desktops and laptops together as they are using same software/OS...
More specifically my webapp needs to support caching via appcache/manifest on iOS, Android & Blackberry (although it would be nice to have all tablets/smartphones) so maybe the question is how to find one of these devices and include the appcache reference, however this looks like it is leading down the path of user agent sniffing which I was hoping to avoid...
Because the browser does check the Appcache.manifast before everything else happens, you have to do an additional serverside detection. You cannot load the appcache.manifest by javascript.
Make a Serverside detection on the Useragent and deliver the HTML with manifest if you get a request from iphone, ipad, android etc. and without manifest in the other cases.
User Agent checking is the best approach. You deliver your site for people who doesn't fake there User Agent.
User agent test with php for mobile devices (just add your devices you need):
Mobile regexp user agent
http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

How to identify the blackberry's browsers

I should identify whether the site is accessed by mobile or web. I am using $_SERVER['HTTP_USER_AGENT'] to identify this. Based on that am loading mobile site.
Everything works fine.
My Problem is, If I change the browser settings in blackberry, from blackberry to Firefox or IE, then it is loading the normal site instead of mobile site.
How to overcome this problem? Please help.
NOTE : Am checking in Blackberry 5
You cannot. You are completely dependent on the browser to tell you what it is. User-agent spoofing blasts that "trust" out of the water.
Instead, you can do "functional" tests in Javascript/CSS that provide features for supporting browsers and fallback mechanisms for non-supporting browsers.
But if you want to switch to a mobile site then you really do just have to do as the browser asks. That's the server's job, anyway; if the user has gone out of their way to pretend that their phone is a normal PC, then that's their choice and your server should just do as it's told.
This is why the option exists in the Blackberry browser in the first place.
As an example, I sometimes find myself making my Android browser spoof itself as Firefox on Windows, so that I can use the normal Facebook site and access features that Facebook haven't implemented on their mobile version.

How to develop a mobile version website, without changing it's domain name?

I want to develop the mobile (also includes iphone,ipad,andriod) version of my original site. But I don't want to create another sub domain like www.m.mydomain.com, can i dynamically change the document root separately for mobile version and the existing one?
I have also noticed that, when I open facebook form iphone or any andriod mobile it opens with it's original domain name like http://www.facebook.com/ bt when i open it from any other mobile like nokia or samsung it comes with http://m.facebook.com/, what is the difference between this 2?
When it comes to iPhone and Android deveices, a website needs very little adjustments because their web browsering capabilities are really good.
For other devices where the web browsing user experience is less satisfying, the site would dynamically switch them to an alternate and less "intense" version of the website.
As for the m.domain.com feature, this is just a subdomain of the domain.com website. Obviously, it represents a mobile version of the main site and will strip out things like flash and javascript basically anything which will be too much for a basic mobile browser.
The dynamic switching of browsers is done via code. There are ways of detecting what browser just requested your website. Based on the information returned you can then redirect to specific scripts which will handle the user requests from then on.
As an example, you can use this standard argument to check the browsers visiting your site:
$_SERVER['HTTP_USER_AGENT']
Hope that helped.
You can differentiate it by User-Agent property either on Apache level, or PHP level. Though that will not be guaranteed because UA can be spoofed. (But how many mobile users would do UA spoofing to pretend they're not mobile?)
you could possibly use some solution:
create a specific mobile website and put it on folder/subdomain and redirect any user with mobile to that site, example: mydomain.com/m/ or m.mydomain.com
example on redirection:
http://detectmobilebrowsers.mobi/
http://mobiforge.com/developing/story/lightweight-device-detection-php
or
you could use responsive webdesign technique, some framework already available for this
http://csswizardry.com/inuitcss/
http://www.columnal.com/
http://stuffandnonsense.co.uk/projects/320andup/
The difference is that high end mobile devices like iphone/android have enough support and functionality to support the original version of the website (zooming/javascript etc). Other devices are better served an basic website developed for mobile devices with a limited display and/or support.
You do want an special URL for your mobile website - as you'd like your mobile website to correctly appear in the mobile search of search engines.
www is actually also a subdomain, but it is so often used, people do not usually realize it, Usually most browsers add it by default and this is why most servers have it enabled by default.
The case you pointed out is also of subdomains. The server check your HTTP request's user-agent and redirects you to the mobile subdomain appropriately.
This isn't really a quick solution for you, but I highly recommend reading Ethan Marcotte's Responsive Web Design articles on alistapart.org. He goes over the philosophy as well as the practical steps to make a site work well for different contexts - desktop browser to mobile device, etc. There are several articles on the site (just search for responsive web design you'll get several of his articles in your results.)

How to enable javascript in client machine using PHP?

Is there any way to enable JavaScript on the client machine using PHP?
You can't do such a thing. It's impossible to modify user preferences stored on their local machines.
You can ask them to enable javascript if it's not the case using the noscript tag.
No, as neither the HTTP protocol or HTML have a feature to do this. To have a website able to enable JavaScript would also be a breach of security. There is also no guarentee that the users browser has JavaScript.
You may wish to look at the <noscript> tags, which allow you to display a message to the user when JavaScript is not active.

Is there a way to force open a new browser window from MOzilla to IE by Onclick function?

Iam getting new window pop up by using window.open(), but need When i click button in Mozilla browser, a new pop window should open in Internet Explorer, Is it possible......
What about non-Microsoft operating systems? Internet Explorer is not available on e.g. Linux. As such this is not possible. Executing arbitrary external applications should not be possible, at least not without the user's explicit permission. That would be a serious security risk.
Why do you want to do this? Does you website not render properly on anything other than IE? If that is so, then you may want to improve the HTML/CSS/Javascript to make it more standards/cross-browser compliant.
Of course, you could just ask or advice the user to view your website in IE. Not a fancy solution, but it has been done that way for ages. Firefox has the IE Tab add-on, which allows users to render pages using IE's render engine inside the Firefox GUI. This makes things slightly more convenient, but it's still a manual process which requires the user's explicit consent.
As a side note, something akin to what you want is possible with the combination IE/Google Chrome Frame. If you add the following meta tag in the target page, then IE with Google Chrome Frame installed will use Google's instead of IE's rendering engine (source):
<meta http-equiv="X-UA-Compatible" content="chrome=1">
I am not aware of any other browser/plugin combination with this feature.
No. Not possible.
If it was possible to run other applications straight from the web, you would already have tons of malware on your computer. Of course this is impossible and not everyone has Windows.
It might be possible if you have control over clients PC (like e.g. company network). There are handlers for special urls in Firefox that allow you to open external application. It requires approval from user. I saw such links for Skype or other IM clients. And one another example is mailto: link.
Well, there are no such compatibilities in DOM, niether there's access necessary for JS to know system capabilities... but I just found this add-on, IE View, that let's you load pages in IE with a right click (using context menu) and mark certain sites to be loaded from IE only.

Categories