tags:

views:

91

answers:

2

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);
+2  A: 

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

RageZ
Thanks Rage! Is tehre a way for me to contact you privately rage?
Doug
@Doug: for? --------------------------
RageZ
Wanted to ask you more about cURL, but it's okay if you don't want to.
Doug
@Doug: not really I don't want to just I think SO users are more available then me ^^ and would provide as much answers as have (or even more) ;-)
RageZ
A: 

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.

Cups
However, this won't check that the UA he's set in his PHP code is valid... at all...
Mez
@Cups: that's client side, we are talking server side here!!!
RageZ
Yes but by looking at a working example of a UA you at least know 1 that works and can therefore eliminate that variable, then another then another ...
Cups