09-25-2007, 08:24 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
To put it simply, no. file_get_contents is a highly primitive function. cURL is the way to go if you want more advanced feedback. I have written you a function that will do just this, if the HTTP code is not 200 (OK) then it will return false, else it will return the contents of the website.
PHP Code:
function file_get_conditional_contents($szURL) { $pCurl = curl_init($szURL); curl_setopt($pCurl, CURLOPT_RETURNTRANSFER, true); curl_setopt($pCurl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($pCurl, CURLOPT_TIMEOUT, 10);
$szContents = curl_exec($pCurl); $aInfo = curl_getinfo($pCurl); if($aInfo['http_code'] === 200) { return $szContents; } return false; }
echo file_get_conditional_contents('http://www.google.com/');
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|