简体   繁体   中英

php automation with curl_exec

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:

<?php
include('server.php');
$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);
    die('111');
}
curl_close($ch);
echo $html;

}
?>

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM