Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP cURL: HTTP headers show 302 and cookies set, cookies are saved and sent, same headers appear?
    text
    copied!<p>This is kind of a carry on from a question asked yesterday: <a href="https://stackoverflow.com/questions/8675611/cant-seem-to-get-a-web-pages-contents-via-curl-user-agent-and-http-headers-b/8675630#8675630">Can&#39;t seem to get a web page&#39;s contents via cURL - user agent and HTTP headers both set?</a></p> <p>I'm attempting to access a url's contents, the problem is the way this url handles request.</p> <p><strong>The url:</strong> <a href="http://www.deindeal.ch/deals/atlas-grand-hotel-2-naechte-30-2/" rel="nofollow noreferrer">http://www.deindeal.ch/deals/atlas-grand-hotel-2-naechte-30-2/</a></p> <p><strong>First request (without cookies):</strong></p> <p>After "learning" to use curl in the command line (props to @d3v3us), a simple request <code>curl -i http://www.deindeal.ch/deals/atlas-grand-hotel-2-naechte-30-2/</code> shows the following:</p> <pre><code>curl -i http://www.deindeal.ch/deals/atlas-grand-hote l-2-naechte-30-2/ HTTP/1.1 302 FOUND Date: Fri, 30 Dec 2011 13:15:00 GMT Server: Apache/2.2.16 (Debian) Vary: Accept-Language,Cookie,Accept-Encoding Content-Language: de Set-Cookie: csrftoken=edc8c77fc74f5e788c53488afba4e50a; Domain=www.deindeal.ch; Max-Age=31449600; Path=/ Set-Cookie: generic_cookie=1; Path=/ Set-Cookie: sessionid=740a8a2cb9fb51166dcf865e35b91888; expires=Fri, 27-Jan-2012 13:15:00 GMT; Max-Age=2419200; Path=/ Location: http://www.deindeal.ch/welcome/?deal_slug=atlas-grand-hotel-2-naechte- 30-2 Content-Length: 0 Connection: close Content-Type: text/html; charset=utf-8 </code></pre> <p><strong>Second request (with cookies):</strong></p> <p>So, I save the cookie using <code>-c</code>, check that it saves as <code>cookie.txt</code>, and run the request again with the addition of <code>-b cookie.txt</code>, getting this:</p> <pre><code>curl -i -b cookie.txt http://www.deindeal.ch/deals/atlas-grand-hotel-2-naechte-3 0-2/ HTTP/1.1 302 FOUND Date: Fri, 30 Dec 2011 13:38:17 GMT Server: Apache/2.2.16 (Debian) Vary: Accept-Language,Cookie,Accept-Encoding Content-Language: de Set-Cookie: csrftoken=49f5c804d399f8581253630631692f5f; Domain=www.deindeal.ch; Max-Age=31449600; P ath=/ Location: http://www.deindeal.ch/welcome/?deal_slug=atlas-grand-hotel-2-naechte-30-2 Content-Length: 0 Connection: close Content-Type: text/html; charset=utf-8 </code></pre> <p>To me this looks like exactly the same contents, minus one or two parameters in the cookie, but maybe I'm overlooking something?</p> <p>I'm attempting to get the curl request to function and return the same contents as when requesting that url via a browser, but I'm not sure what I should do next.</p> <p><strong>Note:</strong> I've tagged this PHP, as I am using PHP to make the requests, I've simply using command line to easily show the returned headers - so if there's any other PHP libraries or methods that would work (better, or in a place that cURL wouldn't), please feel free to suggest any.</p> <p>Any help would be greatly appreciated ;).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload