I have an website. Let's call it http://www.domain.com
. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php
. How can I do that with cURL or another method? I don't want to use iframe
.
Thanks
I have an website. Let's call it http://www.domain.com
. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php
. How can I do that with cURL or another method? I don't want to use iframe
.
Thanks
Depending on your PHP configuration, this may be a easy as using:
$jsonData = json_decode(file_get_contents('https://chart.googleapis.com/chart?cht=p3&chs=250x100&chd=t:60,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:
<?php
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, 'https://chart.googleapis.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World&chof=json');
curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
$jsonData = json_decode(curl_exec($curlSession));
curl_close($curlSession);
?>
Incidentally, if you just want the raw JSON data, then simply remove the json_decode
.
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.
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.
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.
Who needs curl for this simple task?