Re: cURL and response code 302 [message #182115 is a reply to message #182114] |
Fri, 12 July 2013 13:58 |
bill
Messages: 310 Registered: October 2010
Karma:
|
Senior Member |
|
|
On 7/11/2013 3:04 PM, Arno Welzel wrote:
> bill, 2013-07-11 16:51:
>
>> On 7/10/2013 6:12 PM, Arno Welzel wrote:
>>
>>> if($resultcode == 302)
>>> $redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
>>> else
>>> $redirect = '';
>>>
>>> echo 'Effective URL: '.$url.'<br/>';
>>> echo 'HTTP result code: '.$resultcode.'<br/>';
>>> echo 'Redirection: '.$redirect.'<br/>';
>>>
>>> curl_close($ch);
>>> ?>
>>>
>>> See in action at <http://arnowelzel.de/samples/curl-sample.php>
>>>
>>> CURLINFO_REDIRECT_URL is not in the documentation but it was added in
>>> PHP 5.3.7. Also see <http://php.net/ChangeLog-5.php>.
>>>
>>> If this does not work for you (e.g. because you have an older PHP
>>> version), you have to extract the location header "manually".
>>
>> that helps. The php I have available is 5.3, so hints at
>> extracting it "manually?"
>>
>> With thanks and appreciation.
>
> In the example above you will get the headers in $result.
>
> With curl_getinfo(CURLINFO_HEADER_SIZE) you can also check how long the
> header part in $result is (beginning with the first character), so
>
> $headers = substr($result, curl_getinfo(CURLINFO_HEADER_SIZE));
>
> should give you all headers.
>
> HTTP headers are in the form
>
> Header1: Value
> Header2: Value
> [...]
>
> And the redirection URL is
>
> Location: URL
>
> So try to find the "Location: " part and use the remaining text up to
> the line break.
>
> BTW: Using tools like the Firebug AddOn for Firefox help a lot to
> understand HTTP headers.
>
>
Thanks much. Yes I do use Firebug and it is helpful. Just can't
use it with cURL.
I am going to try to upgrade to php5 version 5.4 later today.
Again, thanks for the help.
bill
|
|
|