Results 1 to 2 of 2

Thread: Error "not a valid cURL handle resource" getting HTTP code with CURLINFO_HTTP_CODE

  1. #1
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Question Error "not a valid cURL handle resource" getting HTTP code with CURLINFO_HTTP_CODE

    I'm merely attempting to get the HTTP code (200, 500, 404, 403, etc). However I get the error not a valid cURL handle resource. If I replace $ch with curl_init('http://w3.org/') then all I get is '0' which means it failed. Could someone please help clarify what is going on?

    PHP Code:
    <?php
     $agent 
    'JAB Creations Remote CSS Validator 1.0; Validated by: http://'.$_SERVER['SERVER_NAME'];
     
    $ch curl_init('http://w3.org/');
     
    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);

    $httpcode curl_getinfo($chCURLINFO_HTTP_CODE);
    echo 
    $httpcode;
    ?>

  2. #2
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    I was not aware that setting the $httpcode variable had to be before the cURL execution is closed.

    PHP Code:
    <?php
     $agent 
    'JAB Creations Remote CSS Validator 1.0; Validated by: http://'.$_SERVER['SERVER_NAME'];
     
    $ch curl_init('http://w3.org/');
     
    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);
     
    $httpcode curl_getinfo($chCURLINFO_HTTP_CODE);
     
    curl_close($ch);

    echo 
    $httpcode;
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •