Asked  2 Years ago    Answers:  5   Viewed   70 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?

Sunday, August 14, 2022

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, October 26, 2022

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.

Monday, September 26, 2022

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.

Tuesday, October 4, 2022

What URL are you trying to load? It could be that the page you're requesting has one or more AJAX requests that load content in after the fact. I don't think that cURL can accomodate runtime-loaded information via AJAX or other XHR request.

You might want to look at something like PhantomJS, which is a headless WebKit browser which will execute the page fully and return the dynamically assembled DOM.

Wednesday, November 2, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages