Strawberry
Strawberry

Reputation: 67888

PHP cURl: Can I check if my user agent is working?

I'm writing a cURL script, but how can I check if it's working and passing properly when it's visiting the website?

 $ckfile = '/tmp/cookies.txt';
    $useragent= "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7A400";


    $ch = curl_init ("http://website.com");

    curl_setopt($ch, CURLOPT_AUTOREFERER , true); 
          => true
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // set user agent
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $output = curl_exec ($ch);
    curl_close($ch);

Upvotes: 0

Views: 1507

Answers (2)

Cups
Cups

Reputation: 6896

You'll find the FF extension LiveHTTPHEaders will help you see exactly what happens to the headers when using a normal browsing session.

http://livehttpheaders.mozdev.org/

This will increase your understanding of how your target server responds, and even shows if it redirects your request internally.

Upvotes: 0

RageZ
RageZ

Reputation: 27313

just make a php page like this on your server and try your script on your own url

var_dump($_SERVER);

and check the HTTP_USER_AGENT string.

You can also achieve the same things by looking at the Apache logs.

But I am pretty sure curl is setting the User-Agent string like it should ;-)

Upvotes: 3

Related Questions