thank you for taking the time to trying and help, i really appreciate it. Let me first explain what I am doing, I am trying to get an image from news site by reading it's meta tags. So when i run it on my localhost there is no error, but when i upload the script on my Free Online Subdomaine, then the error appears and some links not that i try but some. Here is the error:
Warning: get_headers(): Failed to enable crypto in /home/vol15_7/byethost7.com/b7_27905999/htdocs/cron/news_cron_1.php on line 81
Warning: get_headers(http://rss.cnn.com/~r/rss/edition_world/~3/6uMCnNwt5F4/index.html): failed to open stream: operation failed in /home/vol15_7/byethost7.com/b7_27905999/htdocs/cron/news_cron_1.php on line 81
and the line 81 is :
$url_redirect = get_headers($link);
I tried this solution but it did not work:
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
I need your help please, here is my code is:
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$url_redirect = get_headers($link);
//var_dump($url_redirect);
$location_redirect = $url_redirect[0];
if (strpos($location_redirect, " 301 ") !== false){
$redirect_array = explode("Location: ", $url_redirect[1]);
$location_url = $redirect_array[1];
} else {
$location_url = $link;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $location_url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($curl);
curl_close($curl);
$htmlentities = htmlentities($result);
if($htmlentities != ""){
// if htmlentites is not empty we make the rest
$htmlentities = htmlentities($result);
libxml_use_internal_errors(true);
$htmlDom = new DOMDocument();
$htmlDom->loadHTML($htmlentities);
//var_dump($htmlDom);
libxml_clear_errors();
$htmlstring = $htmlDom->textContent;
/// code continues from here to grab the image from meta tags ----------------------------
}