FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » cURL and response code 302
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: cURL and response code 302 [message #182111 is a reply to message #182108] Wed, 10 July 2013 22:12 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
bill, 2013-07-10 17:09:

[...]
> using:
>
> function curl_getNoFollow($url, array $get = NULL, array $options
> = array() ){
[...]
> I get:
> url: http://www.mydomain.com/login/login.cfm, http: 302
>
> note the lack of information about the refer to address, which I
> need so I can follow.

A quick & dirty example without any error handling etc. - just to get
the idea:

<?php
$options = array(
CURLOPT_URL => 'http://mydomain.example/foobar',
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_RETURNTRANSFER => true
);

$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$resultcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

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".

HTH


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Install Apache Php Windows 64 bit
Next Topic: Heartbleed bug?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 11:26:35 GMT 2024

Total time taken to generate the page: 0.06244 seconds