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!

5
  • 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 too for a similar case. Commented Nov 24, 2014 at 0:25
  • 1
    Have you enabled allow_url_fopen in your php.ini file? Commented Nov 24, 2014 at 0: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 Commented Nov 24, 2014 at 0:28
  • I have enabled allow_url_fopen. It's on by default. Commented Nov 24, 2014 at 0:30
  • you con't ..you have to use curl Commented Nov 24, 2014 at 0:31

2 Answers 2

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); 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.