Generate Random User Agent String in PHP?

jvm

New member
I want to make a php function to generate a random user agent string
Task: Write a very compact PHP function to return a
random user-agent string.

At the end of this message is a sample list of random user-agent
strings from which you can get field ideas from.

The simplest approach is to just serve a random string from the
list below, but I would rather have a random user-agent string
that is _assembled_ randomly from the strings present below

That was the task, sorry im new to using php user agent strings
 
Martin, I think he is wanted to create random UAs, not get his own, probably for the purpose of a UA switcher or for some other reason, which really isn't important.

What I suggest it finding a site that provides most common UA strings, and then make an array out of them.

Then get a random number and select that index from the array and do what you will with it.

http://google.com/search?q=common+user+agents
http://google.com/search?q=php+arrays
http://google.com/search?q=php+random+number
 
So what's holding you?
It doesn't make sense, because user agent isn't supposed to be random.
Anyway, grab $_SERVER['HTTP_USER_AGENT'] and assign it to string variable.
If you want something to identify user with, use sessions.
 
Back
Top