0

I have a webserver where i call an url and it returns the html contents through this code:

$query = http_build_query(array('year'=>$year));
$url ='http://www.lottologia.com/lotto/?do=past-draws-archive&tab=&' . $query  . '&empty=&group_num_selector=selected&numbers_selector_mode=add&numbers_selected=#main';
$context = stream_context_create(array('http' => array('header' => 'User-Agent: CharlesUserAgent1.0')));
$response = file_get_html($url, false, $context);
$html = str_get_html($response);

It worked until a few days ago. Now the $response return null. I checked the file_get_html method (simple html dom), and the file_get_contents return false. So this is the problem.

  • I checked php.ini and there aren't problems (fopen, etc.);
  • I tried with www.example.com and it returns false.
  • I already tried the curl but it doesn't works. I returns 301 moved permanently. I checked on the web the solution for it but every suggestions don't work.

If possible i want to keep using the file_get_contents/file_get_html.

Christian Felix
  • 644
  • 1
  • 9
  • 28
  • 1
    Maybe they simply blocked your server IP by now, because they do not agree with you scraping their content? https://www.lottologia.com/?do=copyright-and-legal-note – CBroe Aug 18 '20 at 11:59
  • `301 moved permanently` would mean the resource moved. Did you follow the new location? – user3783243 Aug 18 '20 at 12:00
  • Like @user3783243 say 301 means the page has been moved, maybe this answer can help you https://stackoverflow.com/questions/4323985/how-to-get-the-real-url-after-file-get-contents-if-redirection-happens – Baracuda078 Aug 18 '20 at 12:01
  • 1
    (Setting year to `2019` and using just file_get_contents instead of file_get_html, gets me a result that looks like a proper full HTML document, “Past draw results of lottery Gioco del Lotto (2019)”, when I test the code on my machine.) – CBroe Aug 18 '20 at 12:02
  • 1
    Seems all HTTP requests are being redirected. Try `HTTPS` instead. – Nima Aug 18 '20 at 12:17
  • @CBroe I tried from another ip but it doesn't works... – Alessandro Siverino Aug 18 '20 at 12:20
  • @user3783243 Yes I tried to copy the use the new location. Same problem... – Alessandro Siverino Aug 18 '20 at 12:21
  • @CBroe I tried to set 2018 and use file get contents but same error... $link ='https://www.lottologia.com/lotto/?do=past-draws-archive&table_view_type=default&year=2018&numbers='; $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla compatible'))); $response = file_get_contents($link, false, $context); – Alessandro Siverino Aug 18 '20 at 12:23
  • @Nima I tried but nothing... – Alessandro Siverino Aug 18 '20 at 12:23
  • They also could be identifying you by your user agent. I've not seen `CharlesUserAgent1.0` before... but if this is the case they likely don't want you doing what you are doing and will block you another way later. – user3783243 Aug 18 '20 at 12:26
  • @user3783243 I tried Charles searching by web... Now I'm using -> User-Agent: Mozilla compatible' – Alessandro Siverino Aug 18 '20 at 12:28
  • check whether your server has enabled: allow_url_fopen and php_openssl. – Christian Felix Aug 18 '20 at 12:47
  • @ChristianFelix yes they are enabled – Alessandro Siverino Aug 18 '20 at 13:02
  • none can help me?... – Alessandro Siverino Aug 18 '20 at 14:58
  • Could the answers here be helpful? https://stackoverflow.com/questions/6724467/why-doesnt-file-get-contents-work I did the same as @CBroe and it was working for me too. – LisaLisa Aug 18 '20 at 15:04
  • @LisaF I checked, but his problem was that Yahoo can't enable allow_url_open... I have the problem with localhost too – Alessandro Siverino Aug 20 '20 at 11:33

0 Answers0