0

Есть вот такой php скрипт

<?php $url="http://site.ru/index.php?option=com_xmap&view=xml&tmpl=component&id=1";$xml_code = file_get_contents($url);if (file_put_contents($_SERVER['DOCUMENT_ROOT'].'/sitemap.xml', $xml_code))   {      echo "<h1>XML sitemap successfully updated</h1>";      $xml_code = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/sitemap.xml');      $xml_code = str_replace ("</url>", "</url><br>", $xml_code);      echo $xml_code;   }       else echo "<h1>Error!</h1>";?>

При попытке его выполнить получаю

PHP Warning:  file_get_contents(http://site.ru/index.php?option=com_xmap&view=xml&tmpl=component&id=1): failed to open stream: HTTP request failed!  in /var/www/xxxdata/www/site.ru/genmap.php on line 3

Что сделано не так?

1 ответ 1

1

Не пользуйтесь

file_get_contents

он deprecated. Используйте cURL.

function curl($url){        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);        $data = curl_exec($ch);        curl_close($ch);        return $data;    }    $feed = 'http://site.ru/index.php?option=com_xmap&view=xml&tmpl=component&id=1';    $tweets = curl($feed);
1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.