Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the content of a webpage (text) that use https WITHOUT curl on PHP

Tags:

php

https

im using a very simple php script to retrive the text of a webpage;

$homepage = file_get_contents('http://192.168.1.125:6547/quickstatus');
echo $homepage;

But this instruction do not work on https, i dont have support for curl (im using a php compiler), is any way to retrive the content of a page that use https whitout curl???

like image 958
DomingoSL Avatar asked Feb 21 '26 06:02

DomingoSL


2 Answers

I think if the function file_get_contents doesn't work with https address means that your installation of PHP has no openssl extension installed. That's why curl and other solutions will not be an option as well.

like image 151
Gedrox Avatar answered Feb 23 '26 23:02

Gedrox


file_get_contents() will work as long as PHP is compiled with openssl support. If your installation does not include it, you can recompile (or reinstall a binary version of) PHP.

Please note this caveat from the manual:

When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen() to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning.

If you are attempting to connect to a server running IIS, this may also be a solution.

like image 24
George Cummins Avatar answered Feb 23 '26 22:02

George Cummins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!