Reversed Entropy Can entropy ever be reversed?

21Jun/102

Cookies, cURL and PHP without a jar

cURL is one of the best ways of implementing the client side of a RESTful service with PHP, is also really handy to take some data from other websites and do with it whatever you want.

Taking this data can be a problem when you need to autenticate on the third party website using cookies. Rest supports sending and retrieving them, but all the tutorials I've found use txt files to cache those cookies for being able to send them back to the server.

I don't like this approach, so let's see how to grab and store them on-the-fly using a simple regular expresion. First, let's setup a simple authentication page in PHP.

We're going to do at least two connections to the target server, the first one will send the password to the form and grab the cookie, the second one will call again the same server but this time we will send the cookie along our petitions, so we can navigate through private pages like we were a normal user.

Filed under: cURL, PHP Continue reading