tags:

views:

34

answers:

3

I have a site that uses cURL to access some pages, stores the returned results in variables, and then uses these variables within its own page. The script works well except where the target cURL page has a header('Location: ...') command inside it. It seems to just ignore this header command.

The cURL command is as follows...

//Load result page into variable so portions can be allocated to correct variables
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); # URL to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$loaded_result = curl_exec( $ch ); # run!
curl_close($ch);

I've tried changing the CURLOPT_HEADER to 1 but it doesn't do anything.

So how can I allow script redirection within the target urls using cURL to grab the results? By the way, the pages work fine if accessed other than via cURL but iFrames are not an option in this instance.

A: 

You'll want the options CURLOPT_FOLLOWLOCATION and CURLOPT_MAXREDIRS. See the manual.

Artefacto
A: 

If you want cURL to follow redirections add this:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
brant
Excellent. Works like a charm. :)
Das123
A: 

try

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Dan Heberden