Need help with cURL HTTP Code please...
Posted: Thu Jun 12, 2008 3:37 am
For my CSS validator I'm trying to determine if the validator was reached or not. To test the function I merely echo it. I am pretty sure if I echo it and it returns '0' then that means cURL failed to make the connection to the remote website. I know if it does not return '0' that it reached the validator but there was an error validating the code (most likely they changed the needle in their XHTML haystack).
Any way I'm getting the error curl_getinfo(): 20 is not a valid cURL handle resource on line 21 which is line 14 here. I'm not sure why and this feature isn't exactly well documented. On the up side of things I was able to have my script identify itself by setting a useragent so I don't look like a spammer.
Any way I'm getting the error curl_getinfo(): 20 is not a valid cURL handle resource on line 21 which is line 14 here. I'm not sure why and this feature isn't exactly well documented. On the up side of things I was able to have my script identify itself by setting a useragent so I don't look like a spammer.
Code: Select all
function check_css_compliance($css)
{
$agent = 'JAB Creations Remote CSS Validator 1.0; Validated by: http://'.$_SERVER['SERVER_NAME'];
$referer = $css;
$ch = curl_init('http://jigsaw.w3.org/css-validator/validator?uri='.$path_public.'_cache/'.session_id().'.css');
curl_setopt($ch,CURLOPT_USERAGENT, $agent);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
curl_close($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == '200') {$function_result = '200';}
else if ($http_code == '500') {$function_result = '500';}