0

I'm trying to run the following code to get the html of a web page:

$html = file_get_contents("https://www.bet365.com");

But I get these warnings:

PHP Warning:  file_get_contents(): SSL:
PHP Warning:  file_get_contents(https://www.bet365.com): failed to open stream: HTTP request failed!

I've tried setting stream context with different headers, but cannot find a workig solution. What might be the reason for this warning and how can I solve it.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
I. Kone
  • 1
  • 2
  • Does the web server you're connecting to support SSL? i.e. If you visit that link directly in the browser can you view the page or do you get an SSL warning? – War10ck Dec 11 '17 at 14:45
  • 1
    The website probably just forbids you to access it via code, e.g. your PHP. – Tobias F. Dec 11 '17 at 14:45
  • 1
    There's nothing wrong with the site's certificate, it's just denying requests without a user-agent header. You'll need to provide one if you want to access it using a PHP script. – iainn Dec 11 '17 at 14:55
  • Yes, the absence of User-Agent header seemed to cause the problem. Cheers a lot @iainn. – I. Kone Dec 11 '17 at 17:53

1 Answers1

0

This was an enormously helpful link to find:

http://php.net/manual/en/migration56.openssl.php

An official document describing the changes made to open ssl in PHP 5.6 From here I learned of one more parameter I should have set to false: "verify_peer_name"=>false

Similar post Visit it