curl and file_in phpget_Differences between content

  • 2021-06-28 08:49:56
  • OfStack

file_was not found until recently when a web theft program was being runget_content is no longer sufficient.I think when reading remote content, file_get_content is no better than curl except for its convenience.


Main differences:

Learning revealed that curl supports many protocols, including FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP, that is, it can do many file_get_What content can't do.curl can acquire and collect content remotely at php.Implement FTP upload and download for PHP web version;Implement simulated landing;Implement interface docking (API), data transfer;Implement simulated Cookie;Download file breakpoint continuation and so on, 10 points powerful.

Understanding the basic usage of curl1, we found that it is not really difficult, just remember some of the settings, it is difficult to figure out a point, but we can just remember a few of the common ones.

Turn on curl:

Because PHP does not support curl by default, if you want to use curl, you first need to turn it on in php.ini, that is, remove it.extension= php_The semicolon before curl.dll is saved, then restart apache/iis.

Basic grammar:


$my_curl = curl_init();    // Initialization 1 individual curl object 
curl_setopt($my_curl, CURLOPT_URL, "https://www.ofstack.com");    // Set what you need to capture URL
curl_setopt($my_curl,CURLOPT_RETURNTRANSFER,1);    // Set whether the result will be saved in a string or output to the screen. 1 Indicates that the result is saved to a string 
$str = curl_exec($curl);    // Execute Request 
echo $str;    // Output Capture Result 
curl_close($curl);    // Close url request 


Related articles: