file_get_contents cannot get a resourse over https [duplicate] - php

This question already has answers here:
How to get file_get_contents() to work with HTTPS?
(12 answers)
Closed 5 years ago.
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.

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

Related

PHP Warning failed to open stream: No such file or directory [duplicate]

This question already has answers here:
PHP - Failed to open stream : No such file or directory
(10 answers)
Closed 3 years ago.
When i try to access the page give me a php warning :
md5_file(/public_html/: failed to open stream: No such file or directory
But there is a dot after "pages-oubliee" and i don't know where this come from. And how to get rid of this, this dot prevents me from accessing the real directory
it seems the dot comes from a selectPerso.php file, specifically from this line
'fileName'=> './flash/personnalisationV2bis.swf',
Try removing the dot there and see if it helps.

PHP Get 400 error when using file_get_contents with space in URL [duplicate]

This question already has answers here:
file_get_contents with spaces in URL
(2 answers)
Closed 4 years ago.
I am trying to read an external page, but the problem is the url has a space in it. For example:
www.somesite.com/test/main .html
You see a space after main. When you go to the URL via the browser the page comes up. But when I try to use PHPs file_get_contents function I get the error:
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
I tried curl but I get the same 400 error. Any suggestion on how to read the page? I tried using urlencode but get a 404 error.
Thanks!
What browser do you use?
What you can do is to check what exactly your browser sends in its request so it is accepted by server. To do that you may use addons to your browser to inspect send headers.
For the firefox give a try to these:
Modify Headers
live-http-headers
once you know what exactly is send you just need to do the same with cURL that.
Most probably you fail on not sending proper user agent and the server does not serve you seeing you as a script not as a browser.
example how to set user agent:
set-user-agent-php-curl-spoof

YouTube API v3 not working [duplicate]

This question already has answers here:
file_get_contents(): SSL operation failed with code 1, Failed to enable crypto
(21 answers)
Closed 4 years ago.
I am developing a web page and I have a small problem with the YouTube API. I want to get all the information of any YouTube video, but I can not get the data. I have the following PHP code to make the request to the server:
Here is my Code:
$video_get_contents = file_get_contents('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s');
$video_data = json_decode($video_get_contents);
$video_data_title = $video_data->items[0]->snippet->title;
echo $video_data_title;
When I run the previous code I do not get anything, and I do not know why. If I access the URL specified in the code, the JSON code is generated correctly.
When executing my code I get these errors:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s): failed to open stream: operation failed in C:\xampp\htdocs\beta.php on line 4
Could you tell me if the PHP code is correct?
you cant access https url with the file_get_contents,
however for youtube API you can access it using the example in https://developers.google.com/youtube/v3/code_samples/php
and if you still want to access the json in your url, here is a similar question about how to access https with file get contents file_get_contents(): SSL operation failed with code 1. And more

getimagesize() error in php [duplicate]

This question already has answers here:
trying to turn on allow_url_fopen by putting php.ini in wordpress root does not work
(6 answers)
Closed 8 years ago.
So I am using the getimagesize function to get the size of the image. The line I use is the following:
list($width, $height) = getimagesize($imagen);
The variable $imagen is the right one as if I echo it, I get the image url, and the image does exist.
any idea?Edit: allow_url_fopen is on and the error I get is the following:
Warning: getimagesize(): Couldn't resolve host name in /home/u969736199/public_html/web/productos.php on line 43 Warning: getimagesize(http://snapi2.vv.si/web/images/productos/R2203054.jpg): failed to open stream: operation failed in /home/u969736199/public_html/web/productos.php on line 43 http://snapi2.vv.si/web/images/productos/R2203054.jpg
What I get from var_export($imagen); and var_export(is_readable($imagen)); is:
http://snapi2.vv.si/web/images/productos/EE523152.jpg'http://snapi2.vv.si/web/images/productos/EE523152.jpg'false
If you are retrieving a remote image you need to make sure that you enable
allow_url_fopen
in php.ini.
The url you are accessing doesn't resolve. If you go to http://snapi2.vv.si/web/images/productos/EE523152.jpg in the browser you will get a server not found page.

How to check if the remote server images exist? [duplicate]

This question already has answers here:
How can one check to see if a remote file exists using PHP?
(24 answers)
Closed 9 years ago.
I am trying to test if the remote images exist before I process my codes..
I have found this post
How can one check to see if a remote file exists using PHP?
I have tried getimagesize function and file_get_contents function but I got
Warning: getimagesize() [function.getimagesize]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /project/testImages.php on line 147
I can't modify the server configuration in my case.
I am not sure how to solve the errors or if there are another ways to workaround.
Thanks for any help.
Why don't you try cURL with CURLOPT_HEADER set to 1 (or true)? Then just check the returned contents for server response. That's the way I'd do it.

Categories