Using cURL instead of Include or Require

Using cURL in Place of Include() or Require() – PHP

In this write-up, we’ll be going through the benefits of using cURL in place of require or include. If you are on a shared host that doesn’t allow you to change the settings within your php.ini file, then you may be restricted from using the include or require functions. Most of the time, cURL is enabled even if these others aren’t.

Usually, when you include a php script within your page, you use something like




However, some shared hosts will now allow you to do this. A work-around, assuming the cURL library is enabled (check phpinfo()) is


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "/path/to/file.php");

curl_setopt($ch, CURLOPT_HEADER, 0);




Be sure to change the “/path/to/file.php” line to point to the file that you would like to include.

What this code does is “include” the file.php that we have just set as our CURLOPT_URL. This is a very simple, efficient way of including external files in a page, without the need for an iframe, include() (include_once() as well), or require().

Posted in PHP
  • Othersuncomic

    which one is faster??

    • Othersuncomic,

      I have not done a speed test of the two and compared them, but that’s a great idea! Let me put some code snippets together and see what I can do.