cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Stopping redirects being followed from header callback

From: Felix Hassert <felix-sf_at_7val.com>
Date: Tue, 27 May 2008 18:00:53 +0200

Hi,

I am looking for a way to stop libcurl following redirects. To be able
to perform more than one request at a time I use the PHP
curl_multi_exec() function and have CURLOPT_FOLLOWLOCATION on. But
there are certain URLs that I don't want to load and I would like to
stop the redirecting chain.

My first thought was listening to the incoming headers with a callback
function registered as CURLOPT_HEADERFUNCTION. If there was a location
header I check wether I like the redirect url or not and then decide
to call curl_setopt(CURLOPT_FOLLOWLOCATION, false). But it seems, at
that point, it is too late. Curl goes on following redirects until a
2xx response or limit is reached.

While it is possible to change other options in the header callback
(as CURLOPT_ENCODING for example) that are used in the next requests,
disabling CURLOPT_FOLLOWLOCATION seems not work.

Is it totally wrong expecting this behavior? Is there another way of
implementing this?

Felix.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-05-27