Hi, I am trying to write a small PHP script that will POST data to a third-parties' server using the cURL extension. I have no problem using cURL and setting all the POST parameters etc, however the page returned states that my 'session has expired'. I know the third party server sets a session cookie when the web page is visited in the standard way (using a web browser) and I assume this cookie is submitted in the HEADER data along with the POST data ? It would be fairly easy to retrieve a session cookie using cURL (I assume by just scripting cURL to retrieve the webpage where the form is located), but then how do I read that session cookie and then submit it along with the POST data ? I would like to point out that I'm not attempting to write any form of spamming script here. I simply would like to automate several searches that I do at a particular website. Many thanks for your time.
You don't need to send the cookie along with the post, the server you are accessing would attempt to access your cookie. Take a look at: CURLOPT_COOKIEJAR, and CURLOPT_COOKIEFILE. You basically need curl to act as a normal web browser so that it has a user agent and can accept cookies. It would then have a valid session and be able to interact like a normal user.
As I understand it, these options are for setting cookie data which cURL sends. How do I get access to any cookie data that cURL receives ? As far as I can see, cURL doesn't give you access to the response headers. I assume that to make cURL look like a browser, I'd have to set CURLOPT_HTTPHEADER, but one of the parameters in the header is the cookie (as sent by the remote server). I've no idea how to read this cookie with cURL and I don't think it's automatically sent as I've inspected the headers sent using the CURLINFO_HEADER_OUT option of curl_getinfo().