tags:

views:

34

answers:

2

I'm trying to figure out why a cURL process (written in PHP) that used to be working is no longer working. I'm receiving the same data back as what an actual browser is receiving, but I'm not sure if I'm sending the same information as the browser.

Is there a way I can find out what the cURL library in PHP is sending?

Note: I don't have access to the server I'm accessing and I'm actually thinking they're blocking me, so I'm trying to determine what I need to change to copy the browser.

+3  A: 

Since PHP 5.1.3, you can use CURLOPT_HEADER_OUT to get the request headers you sent. I think this might be what you're looking for.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_exec($ch);
var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT));
timdev
+1  A: 

Hi Darryl,

After you run the curl, try this:

$info = curl_getinfo($curlHandle);
echo '<pre>';
print_r($info);
echo '</pre>';

There's a complete list of what curl_getinfo returns here: http://au2.php.net/manual/en/function.curl-getinfo.php

One of which is: CURLINFO_HEADER_OUT - The request string sent

Hope that does it for ya :D

Jamesz
I can't find the headers that are sent in the array of curl info.
Darryl Hein