Page 1 of 2
User Agents.
Posted: Thu Oct 18, 2007 5:51 pm
by JellyFish
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.
Thanks!
Re: User Agents.
Posted: Thu Oct 18, 2007 10:18 pm
by neophyte
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.
Re: User Agents.
Posted: Fri Oct 19, 2007 3:30 am
by JellyFish
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?
Re: User Agents.
Posted: Fri Oct 19, 2007 3:40 am
by Josh1billion
JellyFish wrote:I see. So how might I go about serving different scripts to different browser, server-side?
You have to figure out which browser the user is using (see:
link), and then print() out a different script depending on the browser.
Posted: Fri Oct 19, 2007 5:36 am
by Kieran Huggins
This reeks of bad design - why are you serving different js depending on the browser?
Posted: Fri Oct 19, 2007 8:26 am
by Zoxive
Kieran Huggins wrote:This reeks of bad design - why are you serving different js depending on the browser?
Especially when you can spoof them.
By changing your about:config in Firefox, or this handy addon.
https://addons.mozilla.org/en-US/firefox/addon/59
Posted: Fri Oct 19, 2007 8:30 am
by Josh1billion
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..

Posted: Fri Oct 19, 2007 11:07 am
by RobertGonzalez
I posted a class I had hacked to offer a clean output of User Agent data. I know it is around here somewhere. Some searching might help you find it.
Posted: Sat Oct 20, 2007 3:28 am
by JellyFish
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.
Posted: Sat Oct 20, 2007 3:48 am
by Kieran Huggins
if you're just making up for a few IE bugs, you can always use
IE's conditional comments:
Code: Select all
<head>
<!--[if IE 5]>
<script src="/script/ie5.js"></script>
<link rel="stylesheet" href="/css/ie5.css" />
<![endif]-->
</head>
I would rethink your solution if you're trying to do anything more complicated than this. jQuery includes native cross-browser compatibility!
Posted: Sat Oct 20, 2007 2:18 pm
by JellyFish
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:
Code: Select all
<!--[if IE]-->
<?php echo $headerArgs['IEImports']; ?>
<![end if]-->
<!--[if IE 7]-->
<?php echo $headerArgs['IE7Imports']; ?>
<![end if]-->
<!--[if IE 6]-->
<?php echo $headerArgs['IE6Imports']; ?>
<![end if]-->
<!--[if IE 5.5]-->
<?php echo $headerArgs['IE5.5Imports']; ?>
<![end if]-->
<!--[if lt IE 5.5]-->
<?php echo $headerArgs['IE55LtImports']; ?>
<![end if]-->
<!-- etc... Or something like this. -->
I was thinking that maybe there is a much better solution for this then IE Comments; a php solution maybe.
Posted: Sat Oct 20, 2007 4:17 pm
by RobertGonzalez
Posted: Sat Oct 20, 2007 8:03 pm
by Josh1billion
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.
Posted: Sat Oct 20, 2007 11:42 pm
by RobertGonzalez
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.
Posted: Sun Oct 21, 2007 1:43 am
by Kieran Huggins
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:
Code: Select all
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.