CURL and URL redirection question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Drako

    #1

    CURL and URL redirection question

    I have a database with a lot of links. Every so often I run a script to
    verify if the URLs are still valid. I weed out the ones with the 404
    response.

    However, many responses are of the 303 kind (URL redirection).

    with the following options, CURL does not return the redirection URL.

    $ch = curl_init();
    $ret = curl_setopt ($ch, CURLOPT_URL,
    "http://somedomain.com/somepath.html") ;
    $ret = curl_setopt ($ch, CURLOPT_HEADER, 1);
    $ret = curl_setopt ($ch, CURLOPT_RETURNT RANSFER, 1);
    $ret = curl_setopt ($ch, CURLOPT_NOBODY, 1);
    $ret = curl_setopt ($ch, CURLOPT_TIMEOUT , 60);
    $ret = curl_exec($ch);
    $info = curl_getinfo($c h);
    curl_close($ch) ;

    I would like to retrieve the URL that the URL redirects to so that the
    script can update the URL directly.

    on the command line the following command yields the following result:

    % curl -I "http://somedomain.com/somepath.html"

    HTTP/1.1 303 See Other
    Date: Tue, 15 Nov 2005 06:15:59 GMT
    Server: Apache
    Location: http://somedomain.com/newpath.html
    Vary: Accept-Encoding
    Content-Type: text/html; charset=iso-8859-1
    X-Pad: avoid browser bug


    is it possible to retrieve the 'Location' field via CURL in PHP?

  • Nicholas Sherlock

    #2
    Re: CURL and URL redirection question

    John Drako wrote:[color=blue]
    > with the following options, CURL does not return the redirection URL.[/color]



    Use FollowLocation.

    Cheers,
    Nicholas Sherlock

    Comment

    • John Drako

      #3
      Re: CURL and URL redirection question

      On Tue, 15 Nov 2005 02:38:09 -0500, Nicholas Sherlock wrote
      (in article <dlc3ab$q8i$1@l ust.ihug.co.nz> ):
      [color=blue]
      > John Drako wrote:[color=green]
      >> with the following options, CURL does not return the redirection URL.[/color]
      >
      > http://php.inspire.net.nz/manual/en/...url-setopt.php
      >
      > Use FollowLocation.[/color]

      Thanks, that worked :)

      CURL has so many options that it's a bit confusing to read all of them.

      Comment

      Working...