0

For when web-hosts don't allow file_get_contents (either directly, or by allow_url_fopen). I want to put together a list of alternatives. Can anyone offer suggestions? I found that cURL could be used, but the code below doesn't return anything in $output.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"php://input" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
OBV
  • 1,169
  • 1
  • 12
  • 25

1 Answers1

-1

File_get_contents alternative (CURL):

<?php

function file_get_contents_curl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

?>

Note: not made by me, found this on the internet some weeks ago.

  • It worked for me. Just call it like this `$something = file_get_contents_curl('http://some-site.com/');` – user2941923 Nov 02 '13 at 15:50
  • 1
    Oops my bad but I found a question about the same 'topic', http://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to , maybe it's use full. – user2941923 Nov 02 '13 at 17:34
  • Ok well that doesnt help me, but thanks for replying. – OBV Nov 02 '13 at 21:58