By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,182 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,182 IT Pros & Developers. It's quick & easy.

CURL and URL redirection question

P: n/a
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_RETURNTRANSFER, 1);
$ret = curl_setopt ($ch, CURLOPT_NOBODY, 1);
$ret = curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
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?

Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
John Drako wrote:
with the following options, CURL does not return the redirection URL.


http://php.inspire.net.nz/manual/en/...url-setopt.php

Use FollowLocation.

Cheers,
Nicholas Sherlock
Nov 22 '05 #2

P: n/a
On Tue, 15 Nov 2005 02:38:09 -0500, Nicholas Sherlock wrote
(in article <dl**********@lust.ihug.co.nz>):
John Drako wrote:
with the following options, CURL does not return the redirection URL.


http://php.inspire.net.nz/manual/en/...url-setopt.php

Use FollowLocation.


Thanks, that worked :)

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

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.