php curl cookie_session and relocation -
situation:
when entering site, sets session cookie , redirects itself.
problem:
when using curl follow_relocation
, cookie_session
, not apply cookie after redirect , ends maximum redirection limit reached error.
code:
curl_setopt($ch, curlopt_url,$url); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_cookiesession, 1); curl_setopt($ch, curlopt_interface, $ip); curl_setopt($ch, curlopt_verbose, 1);
verbose output:
* connect() www.thesite.org port 80 (#0) * trying x.x.x.254... * name 'x.x.29.61' family 2 resolved 'x.x.29.61' family 2 * local port: 0 * connected * connected www.thesite.org (x.x.x.254) port 80 (#0) > / http/1.1 host: www.thesite.org accept: */* < http/1.1 302 moved temporarily < date: wed, 31 jul 2013 15:14:05 gmt < server: apache < cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < pragma: no-cache < expires: mon, 17 jul 1978 05:00:00 gmt < last-modified: wed, 31 jul 2013 15:14:05 gmt < set-cookie: jsessionid=0a2488ff811ccdab6a6c95c12aa3f4f8.db4b9335df549e1fcf56cf5bd8; path=/ < location: http://www.thesite.org/ < content-length: 0 < vary: accept-encoding < content-type: text/html < * connection #0 host www.thesite.org left intact * issue request url: 'http://www.thesite.org/' * re-using existing connection! (#0) host www.thesite.org * connected www.thesite.org (x.x.x.254) port 80 (#0) > / http/1.1 host: www.thesite.org accept: */* < http/1.1 302 moved temporarily < date: wed, 31 jul 2013 15:14:06 gmt < server: apache < cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < pragma: no-cache < expires: mon, 17 jul 1978 05:00:00 gmt < last-modified: wed, 31 jul 2013 15:14:06 gmt < set-cookie: jsessionid=5a80785b002d8c37f73f798b75a090b4.47ef37a843f03a8253f26bc644; path=/ < location: http://www.thesite.org/ < content-length: 0 < vary: accept-encoding < content-type: text/html < * connection #0 host www.thesite.org left intact * issue request url: 'http://www.thesite.org/' * re-using existing connection! (#0) host www.thesite.org * connected www.thesite.org (x.x.x.254) port 80 (#0) > / http/1.1 host: www.thesite.org accept: */* etc...
the question is:
what doing wrong? how make work? of course connect 2 times , set manually, it's not do, that's why using curl
, not file_get_contents()
.
your code doesn't show you're using cookiefile store information between page loads.
add following lines , should work better.
$cookie_file='cookies.txt'; //change wherever want. curl_setopt($ch, curlopt_cookiefile, $cookie_file); curl_setopt($ch, curlopt_cookiejar, $cookie_file);
Comments
Post a Comment