You are here:  » Add User-Agent


Add User-Agent

Submitted by jaxdevil on Tue, 2008-06-10 14:02 in

How can I make the script send User-Agent data? Yahoo Shopping will not allow access if the sript does not send user-agent data. it does not have to be unique for each user but it does need to send a user-agent. Please advise.

Thanks,
SK

Submitted by support on Tue, 2008-06-10 14:28

Hi,

You should be able to do this using int_set(). Try the following code before your call to MagicParser_parse()...

  ini_set('user_agent', 'Your-User-Agent-Here');

(note that PHP does send a user-agent by default, normally "PHP/Version" - so bear that in mind, your problem might be something else)

Cheers,
David.

Submitted by jaxdevil on Tue, 2008-06-10 15:01

I tried that but it still is telling me the user-agent is invalid (and the one I listed is one of the ones they list as valid)

Any ideas?

Thanks,
SK

Submitted by support on Tue, 2008-06-10 16:13

Hi,

It is probably worth confirming that ini_set is actually having an effect. One way to do this is to try and fopen() a file on your server, and then look at the request in the access logs to confirm that the user-agent has been configured as expected. It is possible of course that your PHP installation does not let you override the user-agent using ini_set().

Are you able to try that?

The other option of course is to use CURL, although this requires your PHP installation to have been built with the CURL libraries included. You can see the code required for that in the following thread:

http://www.magicparser.com/node/61

The code in that thread doesn't set the user-agent, but you can do so using this code:

curl_setopt($ch, CURLOPT_USERAGENT, "required user-agent here");

Cheers,
David.

Submitted by jaxdevil on Tue, 2008-06-10 18:17

No need, the first fix you gave me ended up working. Something else was wrong too but I figured that out. The fix worked.

Thanks,
SK