PHP header redirect inside page caused by cURL

I have a site that uses cURL to access some pages, stores the returned results in variables, and then uses these variables on its own page. The script works well unless the cURL landing page contains a heading ("Location: ...") 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 tried changing CURLOPT_HEADER to 1, but does nothing.

So, how can I enable script redirection in destination URLs using cURL to capture the results? By the way, pages work fine if they are accessed differently than through cURL, but iFrames is not an option in this case.

+3
3

, cURL , :

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
+2

CURLOPT_FOLLOWLOCATION CURLOPT_MAXREDIRS. . manual.

+1

to try

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+1
source

Source: https://habr.com/ru/post/1749525/


All Articles