Hey, what does a user agent string have in it? I know it's a string from a web browser and other place, mainly the user.
But what's up with it? What is it made up of? I need to know more about this string in order to check it for validity.
So if anyone have any information on the user agent string that explains it, in a straightforward fashion. Or if you would like to explain it, I'd so much appreciate all the help I could get.
Its a string that's passed in your http request that supposedly defines what what kind of browser you are connecting with. Unfortunately they can't be trusted. They can be altered by users. They can be altered on every request. If you want to observe them you should install the "live headers" extension for Firefox. Then you can watch them as they requests cycle. There's also a Firefox extension called Modify Headers. Through which you could modify your User-Agent header to be whatever you want.
neophyte wrote:Its a string that's passed in your http request that supposedly defines what what kind of browser you are connecting with. Unfortunately they can't be trusted. They can be altered by users. They can be altered on every request. If you want to observe them you should install the "live headers" extension for Firefox. Then you can watch them as they requests cycle. There's also a Firefox extension called Modify Headers. Through which you could modify your User-Agent header to be whatever you want.
I see. So how might I go about serving different scripts to different browser, server-side?
There could be a good reason for what he's trying to do. I could see it if you need to use a hack to make a script compatible with a certain browser. In that case, though spoofing browsers would be possible, it'd also be very pointless..
I'm constructing a server-side architecture, if you will, so that I could easily set variables such as $headerArgs['cssImports'] then include my header.php script which echos those variables.
My newest members of the array will be something like: $headerArgs['IECssImports'] or headerArgs['IE6JsImports']. This gives me the ability to add script and stylesheet imports without having to change my global header.php script.
Hopefully that make sense. But what I need to know now is: How do I serve different variables to different browser on the server's side? HTTP_USER_AGENT is the only server-side solution that I know of, at them moment.
This is what I was thinking of doing. But I would like my scripts to be flexible enough to import css code for all IE5.5+ browsers. In order to be extremely flexible with IECCSS (IE Conditional Comment Style Sheets) I would have to write this:
Hey that looks pretty cool. Hm.. maybe even better if you could add PSP, Wii, and mobile support. I don't know much about mobile web browsing, but the PSP thing would be useful since you could format a page to fit the PSP's screen better if you knew the user was browsing via PSP.
All that class really does is take what is presented by the user agent and parses into something more useable. If the UA presents itself as a Wii or iPhone or anything else, the class will be able to tell and report it.
I can't help but feel like you're approaching this from the wrong angle. For the most part the Javascript/CSS will be the same in each browser. In Javascript specifically, you should be testing not for platforms but instead for method availability:
if(methodname){
v = methodname(data);
}else{
v = workaround();
}
jQuery supports cross browser scripting out of the box, as do some other frameworks. Use them!
As for Wii or PSP support: if they're really important target platforms you should consider writing a custom view for each. Take a look at http://iphone.facebook.com for inspiration.