Asked  7 Months ago    Answers:  5   Viewed   33 times

I have an website. Let's call it Now, on this I want to display the file contents of How can I do that with cURL or another method? I don't want to use iframe.



echo file_get_contents('');

Who needs curl for this simple task?

Wednesday, March 31, 2021
answered 7 Months ago

Depending on your PHP configuration, this may be a easy as using:

$jsonData = json_decode(file_get_contents(',40&chl=Hello|World&chof=json'));

However, if allow_url_fopen isn't enabled on your system, you could read the data via CURL as follows:

    $curlSession = curl_init();
    curl_setopt($curlSession, CURLOPT_URL, ',40&chl=Hello|World&chof=json');
    curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);

    $jsonData = json_decode(curl_exec($curlSession));

Incidentally, if you just want the raw JSON data, then simply remove the json_decode.

Wednesday, March 31, 2021
answered 7 Months ago

You should only call curl_close() when you know you're done with that particular handle, or if switching from its current state to a new one (ie: changing a ton of options via curl_setopt() would be faster by going from a clean new handle than your current "dirty" one.

The cookiejar/file options are only strictly necessary for maintaining cookies between seperate curl handles/invokations. Each one's independent of the others, so the cookie files are the only way to share between them.

Wednesday, March 31, 2021
answered 7 Months ago

Use file_put_contents()

$image = file_get_contents('');
file_put_contents('./myDir/myFile.gif', $image);
Saturday, May 29, 2021
answered 5 Months ago

This information is not sent in the HTML code, but in the HTTP headers. If the curl_getinfo call does not return it, the server did not send it in its HTTP headers.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :