php curl – php automation with curl_exec-ThrowExceptions

Exception or error:

I need to execute some php pages with curl_exec but I’m getting the message “Moved Permanently” and the pages isn’t executing.

What Am I forgetting?

I have all the pages in one mysql table and my code is bellow:

$results_path = mysqli_query($conn, "SELECT * FROM table_script");

while ($row = mysqli_fetch_array($results_path)) {

$file_string = $row['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_string);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

if(($html = curl_exec($ch)) === false)
    echo 'Curl error: ' . curl_error($ch);
echo $html;

How to solve:

You need to follow the location if there is a redirect. You can accomplish that by simply add this line before the execute.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Note, to correct the curl handle on line

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");


curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

Leave a Reply

Your email address will not be published. Required fields are marked *