Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #10066

Re: cURL and response code 302

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: cURL and response code 302
Date Thu, 11 Jul 2013 21:04:57 +0200
Lines 59
Message-ID <51DF01D9.9060502@arnowelzel.de> (permalink)
References <krem8f$epd$1@speranza.aioe.org> <uoBCt.963$t_.539@newsfe11.iad> <krh5it$s6a$1@speranza.aioe.org> <51DC1D1D.3090905@arnowelzel.de> <krh82d$4hl$1@speranza.aioe.org> <51DC2A36.7090005@arnowelzel.de> <krjtg7$1j1$1@speranza.aioe.org> <51DDDC3D.9010609@arnowelzel.de> <krmgp9$jl6$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Trace individual.net A2LMbQBpVmvcZnBsaW8pzAiBBgVbiLQdkHR7P0GLTsbYfC4j6d
Cancel-Lock sha1:qEs7paEMhkMftGY6Hr3t/zAuCzU=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7
In-Reply-To <krmgp9$jl6$1@speranza.aioe.org>
Xref csiph.com comp.lang.php:10066

Show key headers only | View raw


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.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

cURL and response code 302 bill <william@TechServSys.com> - 2013-07-08 11:35 -0400
  Re: cURL and response code 302 Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-07-08 09:02 -0700
    Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-09 10:09 -0400
      Re: cURL and response code 302 Arno Welzel <usenet@arnowelzel.de> - 2013-07-09 16:24 +0200
        Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-09 10:51 -0400
          Re: cURL and response code 302 Arno Welzel <usenet@arnowelzel.de> - 2013-07-09 17:20 +0200
            Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-10 10:40 -0400
            Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-10 11:09 -0400
              Re: cURL and response code 302 Arno Welzel <usenet@arnowelzel.de> - 2013-07-11 00:12 +0200
                Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-11 10:51 -0400
                Re: cURL and response code 302 Arno Welzel <usenet@arnowelzel.de> - 2013-07-11 21:04 +0200
                Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-12 09:58 -0400
          Re: cURL and response code 302 Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-07-09 21:44 -0700
            Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-10 10:42 -0400
              Re: cURL and response code 302 Scott Johnson <noonehome@chalupasworld.com> - 2013-07-10 16:13 -0700
                Re: cURL and response code 302 bill <william@TechServSys.com> - 2013-07-12 09:59 -0400
            Re: cURL and response code 302 kyrpog83@gmail.com - 2014-04-10 10:23 -0700

csiph-web