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