View Single Post
Old 09-25-2007, 08:24 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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($pCurlCURLOPT_RETURNTRANSFERtrue);
    
curl_setopt($pCurlCURLOPT_FOLLOWLOCATIONtrue);
    
curl_setopt($pCurlCURLOPT_TIMEOUT10);

    
$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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote