0

I'm trying to take the content of a site by file_get_contents(), but it doesn't work. I already tried to follow these codes here, but it doesn't work. This is the code I have:

$url = "https://www.cb01.uno/";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
          "Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
          "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
  )
);

$context = stream_context_create($options);
echo $file = file_get_contents($url, false, $context);

It returns nothing. I tried with other site like https://www.w3schools.com and it works, so the problem isn't the HTTPS

EDIT: I tried this solution HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable and now it display:
Not Found
The requested URL /cdn-cgi/l/chk_jschl was not found on this server.

Riccardo
  • 21
  • 1
  • 9
  • When I run your code I get: `Warning: file_get_contents(https://www.cb01.uno/): failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable`. What are your error reporting settings? – Álvaro González Oct 24 '17 at 14:50
  • I tried to add `error_reporting(E_ALL);` before `$url = "https://www.cb01.uno/";` and I don't have any error – Riccardo Oct 24 '17 at 14:55
  • You may also need `ini_set('display_errors', true);`. Whatever, `file_get_contents()` can be hard to diagnose. You need to check the [`$http_response_header` variable](https://stackoverflow.com/questions/15620124/http-requests-with-file-get-contents-getting-the-response-code). – Álvaro González Oct 24 '17 at 15:07
  • Thanks @ÁlvaroGonzález, now it display this: _Warning: file_get_contents(https://www.cb01.uno/): failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable_ – Riccardo Oct 24 '17 at 15:14
  • There you are. It's possible they're detecting you are a script and blocking you. – Álvaro González Oct 24 '17 at 15:19
  • I also tried this code https://stackoverflow.com/questions/17061801/http-request-failed-http-1-1-503-service-temporarily-unavailable and now it works but says _Not Found The requested URL /cdn-cgi/l/chk_jschl was not found on this server._ – Riccardo Oct 24 '17 at 15:27

0 Answers0