0

My problem that curl not working in the right way on my hosting but working well in my localhost.

Here's the code that i used to test:

$url = 'https://www.instagram.com/nasa/?__a=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); 
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo style_print_r( $result );

In my localhost the result of the code is this: enter image description here

But in my hosting the result is this: enter image description here

In my hosting, it seems that its try to load the whole page :(

How can solve this problem?

EDIT: That's the source code that printiny in my hosting: enter image description here

John
  • 161
  • 1
  • 13
  • Run `phpinfo()` on your shared hosting to see whats what on differences with your local environment. That is make a script or insert a line into existing one with `phpinfo()`. – GetSet Feb 01 '20 at 11:35
  • It may also be worth checking for errors - https://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php – Nigel Ren Feb 01 '20 at 11:43
  • When you say working differently on localhost and your hosting, do you mean you are running the exact same Php code above on each? – Progrock Feb 01 '20 at 11:46
  • @Progrock Yes the exact but in my localhost it's wokring right but in my hosting it's loading the whole page like the instagram logo and the metas and scripts and styles. – John Feb 01 '20 at 11:59
  • Try getting a verbose dump of your curling see: https://stackoverflow.com/a/3760294/3392762 – Progrock Feb 01 '20 at 12:18
  • @Progrock same thing :( – John Feb 01 '20 at 12:27

1 Answers1

0

Please check the Curl in your shared hosting

If you want to check whether the hosting service you are using has activated CURL or not, please create a php file with the following contents:

<?php
   // Script to test if the CURL extension is installed on this server

   // Define function to test
   function _is_curl_installed() {
       if  (in_array  ('curl', get_loaded_extensions())) {
   Â Â Â Â Â Â Â  return true;
   Â Â Â  }
   Â Â Â  else {
   Â Â Â Â Â Â Â  return false;
   Â Â Â  }
   }

   // Ouput text to user based on test
   if (_is_curl_installed()) {
      Â  echo "cURL is <span style=\"color:blue\">installed</span> on this server";
   } else {
      Â  echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
   }
?>

You can save the file with any file name, for example curl.php, after you save it, please access it via your web browser, for example at the address www.yourdomain.com/curl.php to find out the results.