[thelist] [PHP] Visiting a page in the background?
Christian Heilmann
codepo8 at gmail.com
Fri May 2 04:51:47 CDT 2008
kasimir-k wrote:
> Tris scribeva in 2008-04-30 12:50:
>
>> Hmmm, I just tried making the URL to call http://www.bbc.co.uk and I got back:
>> Resource id #4
>>
>
> So you are still trying to use fopen()? It is supposed to return a
> resource. You can then read and write the opened file using this
> resource. fopen() on its own does not make a HTTP request.
> <http://php.net/fopen>
>
> A lot easier is to use file() or file_get_contents()
> <http://php.net/file> or <http://php.net/file-get-contents>
>
> .k
>
Most PHP setups will not allow you to open a file on another server
though, for that you need to use cURL, provided your server has it:
$url = 'http://yahoo.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$content then has the HTML content of the page.
More information about the thelist
mailing list