homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

http user agent
want to assign

Msg#: 4202533 posted 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.



Msg#: 4202533 posted 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?


Msg#: 4202533 posted 6:59 am on Sep 19, 2010 (gmt 0)

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);


Msg#: 4202533 posted 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?)


Msg#: 4202533 posted 10:43 am on Sep 19, 2010 (gmt 0)

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....


Msg#: 4202533 posted 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?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved