Using CURL to get the HTTP status code of a URL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Soper

    #1

    Using CURL to get the HTTP status code of a URL

    I would like to get the HTTP status code of a URL using PHP. I think
    CURL is the way to go but I can't see how to do it. I see I can use
    curl_getinfo on the CURL session after I've curl_exec'ed it but I
    can't see what options I should set to get CURL to only get the HTTP
    status code and not retrieve the data at the URL.

    Help gratefully received!

    Thanks,
    Geoff
  • Jochen Daum

    #2
    Re: Using CURL to get the HTTP status code of a URL

    Hi,

    On 29 Mar 2004 03:26:11 -0800, geoff.google.no spam@alphaworks .co.uk
    (Geoff Soper) wrote:
    [color=blue]
    >I would like to get the HTTP status code of a URL using PHP. I think
    >CURL is the way to go but I can't see how to do it. I see I can use
    >curl_getinfo on the CURL session after I've curl_exec'ed it but I
    >can't see what options I should set to get CURL to only get the HTTP
    >status code and not retrieve the data at the URL.[/color]


    I think you want to send a HEAD request.

    www.php.net/curl has heaps of examples, a HEAD request has IMO the
    same structure as a GET request.

    HTH, Jochen
    --
    Jochen Daum - Cabletalk Group Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    http://sourceforge.net/projects/phpdbedittk/

    Comment

    • Manuel Lemos

      #3
      Re: Using CURL to get the HTTP status code of a URL

      Hello,

      On 29 Mar 2004 03:26:11 -0800, geoff.google.no spam@alphaworks .co.uk
      (Geoff Soper) wrote:[color=blue]
      >I would like to get the HTTP status code of a URL using PHP. I think
      >CURL is the way to go but I can't see how to do it. I see I can use
      >curl_getinfo on the CURL session after I've curl_exec'ed it but I
      >can't see what options I should set to get CURL to only get the HTTP
      >status code and not retrieve the data at the URL.[/color]

      You may want to try this HTTP client class that lets you do exactly what
      you want.

      http://www.phpclasses.org/httpclient

      --

      Regards,
      Manuel Lemos

      PHP Classes - Free ready to use OOP components written in PHP
      http://www.phpclasses.org/

      PHP Reviews - Reviews of PHP books and other products
      http://www.phpclasses.org/reviews/

      Metastorage - Data object relational mapping layer generator

      Comment

      Working...