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

curl-and-php

Re: Not able to follow redirections

From: Gowranga <gowranga_at_serc.iisc.ernet.in>
Date: Sat, 16 Jun 2007 17:34:58 +0530 (IST)

> You should probably enable cookies to get things working just like your
browser does.
>
>> HTTP/1.0 302 Moved Temporarily
>> Location: http://www.google.co.in/
>
> You got a redirect!
>
>> HTTP/1.0 200 OK
>
> ... and the subsequent response was fine too.
>

I have included cookies and the script is as follows:

---------------------------------
<?php
$url = "http://www.google.com";
$string="PREF=ID";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, "xx1.xx.xx.xx:port");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIE, $string);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.7.13) Gecko/20060414");
curl_exec($ch);

$url = "http://www.google.co.in";
$string="PREF=ID";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, "xx1.xx.xx.xx:port");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIE, $string);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.co.in");
//curl_setopt($ch, CURLOPT_COOKIESESSION, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.7.13) Gecko/20060414");
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

---------------------------------
The contents of /tmp/cookie.txt(permissions set as 0755) appear as

# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

.google.com TRUE / FALSE 2147483647
PREF ID=cf2bba2e5154b172:TM=1181963457:LM=1181963457:S=Gs42Z_ZkJ7JMflUE
.google.co.in TRUE / FALSE 2147483647
PREF ID=b90f5f526bde641b:TM=1181963457:LM=1181963457:S=H6m7RvfwUB-MnJeN
---------------------------------
I do get a favourable response on the browser:

---------------------------------
HTTP/1.0 302 Moved Temporarily Location: http://www.google.co.in/
Cache-Control: private Content-Type: text/html Server: GWS/2.1
Content-Length: 221 Date: Sat, 16 Jun 2007 10:55:12 GMT X-Cache: MISS from
xx1.xx.xx.xx Proxy-Connection: close
302 Moved
The document has moved here. HTTP/1.0 200 OK Cache-Control: private
Content-Type: text/html; charset=UTF-8 Server: GWS/2.1 Date: Sat, 16 Jun
2007 10:55:13 GMT X-Cache: MISS from xx1.xx.xx.xx Proxy-Connection: close
---------------------------------

However, the response is the same even when CURLOPT_FOLLOWLOCATION
option is not chosen. And the URL does not change in either case.

Thanks

-gowranga

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-06-17