3

I'm trying to get some data from a website that is not mine, using this code.

<?
$text = file_get_contents("https://ninjacourses.com/explore/4/");
echo $text;
?>

However, nothing is being echo'd, and the string length is 0.

I've done this method before, and it has worked no problem, but with this website, it is not working at all.

Thanks!

BryanLavinParmenter
  • 416
  • 1
  • 8
  • 20
  • Don't think it will work very well with HTTPS... The manual says it returns false on failure - would pay to var_dump() the output to be sure. See [this article here](http://stackoverflow.com/questions/1975461/file-get-contents-with-https) too for a similar case. – scrowler Nov 24 '14 at 00:25
  • 1
    Have you enabled `allow_url_fopen` in your `php.ini` file? – Cyclonecode Nov 24 '14 at 00:27
  • If you enable error_reporting you will se the following error: `SSL operation failed with code 1. OpenSSL Error messages: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure` – Cyclonecode Nov 24 '14 at 00:28
  • I have enabled `allow_url_fopen`. It's on by default. – BryanLavinParmenter Nov 24 '14 at 00:30
  • you con't ..you have to use [curl](http://php.net/manual/en/ref.curl.php) – Rajib Ghosh Nov 24 '14 at 00:31

2 Answers2

4

I managed to get the contents using curl like this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://ninjacourses.com/explore/4/");
$result = curl_exec($ch);
curl_close($ch);
Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
2

cURL is a way you can hit a URL from your code to get a html response from it. cURL means client URL which allows you to connect with other URLs and use their responses in your code

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://ninjacourses.com/explore/4/");
$result = curl_exec($ch);
curl_close($ch);

i think this is useful for you curl-with-php and another

Community
  • 1
  • 1
Rajib Ghosh
  • 640
  • 3
  • 12