Member-only story

Retrieving cookies from a cURL call response in PHP

Paolo Montalto
3 min readApr 2, 2020

--

Many people despise PHP because they don’t believe it to being a sufficiently structured language and they think the programmer is left free to make the worst spaghetti coding.

Anyway I believe bad programming comes from a bad programmer, though some languages may enforce correctness and type safety above others.

Beside this we must cope with the fact that most commercial web hostings support this language out of the box and, though I prefer to implementing my services and web apps in other languages / frameworks (e.g. .Net Core, Spring Boot, etc.), I’ve been frequently asked to deliver a product in PHP.

So I always tried to make the best of these opportunities and write the more readable and good code possible.

Recently I had to deliver a REST API which made usage of third party APIs from different publishers. Some of them relied on cookies to keep track of the session status, thus I found myself in front of this question:

How can I retrieve cookies returned from an API call?

So I started to going through the cURL (which I used to perform remote API calls) references and found that PHP cURL implementation provides the ability to set a callback function to listen for response headers.

--

--

Paolo Montalto
Paolo Montalto

Written by Paolo Montalto

Android Engineer, freelance, mobile developer, software craftsman, guitar strummer, husband, father, humble.

Responses (1)