Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

http user agent

want to assign



2:58 am on Sep 16, 2010 (gmt 0)

When I read an internet page with the file() command, the http_user_agent is reported as nothing. I want to put something there for the user_agent. I found an example here under php/3388602.htm but I can't get it to work. Not sure what should go in the Host: parameter
I'm new to this website, and having a bit of difficulty figuring it out.


2:44 am on Sep 19, 2010 (gmt 0)

It's has been several days and I haven't gotten a reply. The reason I need this is I offer a service which entails looking at things on the user site, and I need a way for them to let me through their bad bot function. Does anyone know how to make this work?


6:59 am on Sep 19, 2010 (gmt 0)

5+ Year Member

i use curl for this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $fp);
curl_setopt($ch, CURLOPT_REFERER, "example.com");
curl_setopt($ch, CURLOPT_USERAGENT, "example.com (+http://www.example.com/policy/)");
$string = curl_exec($ch);


8:17 am on Sep 19, 2010 (gmt 0)

I did a quick scan of curl, but I don't know it at all.
Trying to relate this example to what I saw there has me totally confused.

The curl_exec does the read of the website?
A user agent is not normally a url, could it be something like simply "MyAgent"?
What is a referer?
What is $fp pointing to? (the curl example at php.net for reading a website uses a fopen(), do I need something like that to get the $fp?)


10:43 am on Sep 19, 2010 (gmt 0)

5+ Year Member

yes, curl_exec reads the website.

$fp holds the url you want to read. For example $fp='http://www.google.com';

Useragent is just a string, so 'myagent' would be ok.

Just give it a try....


11:29 pm on Sep 19, 2010 (gmt 0)

Well, that worked. Thanks. I'll have to learn more about curl.

Is the REFERER necessary?

Featured Threads

Hot Threads This Week

Hot Threads This Month