Handling phpsessid cookies ?

Hi

I'm running a web client on my Arduino and have it working nicely making POST messages to a piece of equipment which presents a webpage to control it.

However I now wish to control a Pluto ADALM which presents a php webpage and sends a phpsessid cookie.
I figure I need to capture this cookie and send it back with my data / command.

Can someone point me toward some example code I could use as a starting point ?

Regards Tim

Thanks for that link it has helped my understanding of the php process.

I'm still to figure out how to implement it on an arduino working as a client - ie how to parse out the cookie after the initial connection such that I can include when sending data back to the server.

Regards Tim

read through the incomming HTTP-Header fields and store that information.
On the next request - add this to your next outgoing message (as additional header field). I'm not shure about the proper naming convention, but this should be findable via Google...

edit:
ok should be straight forward: HTTP cookie - Wikipedia

you receive several "Set-Cookie" and concatenate them in your next request as "Cookie".

edit 2:
well, that's seems to work. If you send the received cookie, at least the Arduino test page from the webclient example doesn't send the __cfduid again:

22:03:10.503 -> try www.arduino.cc connected IP 172.67.5.5
22:03:10.863 ->
22:03:10.863 -> client connected
22:03:10.863 -> HTTP/1.1 200 OK
22:03:10.863 -> status code=200
22:03:10.863 -> reason phrase=OK

22:03:10.863 -> Date: Tue, 27 Oct 2020 21:03:12 GMT
22:03:10.863 -> Content-Type: text/plain
22:03:10.903 -> Content-Length: 6
22:03:10.903 -> Connection: close
22:03:10.903 -> Set-Cookie: __cfduid=d93b605c6df40be709439f9f96cf63b041603832592; expires=Thu, 26-Nov-20 21:03:12 GMT; path=/; domain=.arduino.cc; HttpOnly; SameSite=Lax
22:03:10.903 -> D162 Set-Cookie found
22:03:10.903 -> Last-Modified: Mon, 31 Aug 2020 09:25:41 GMT
22:03:10.903 -> ETag: "5f4cc215-6"
22:03:10.903 -> Accept-Ranges: bytes
22:03:10.903 -> CF-Cache-Status: DYNAMIC
22:03:10.903 -> cf-request-id: 060d7850370000cbb4dd8f6000000001
22:03:10.903 -> Server: cloudflare
22:03:10.903 -> CF-RAY: 5e8f5cc6afc7cbb4-VIE
22:03:10.903 ->
22:03:10.903 -> 10813
22:03:10.903 ->
22:03:10.903 -> body=
22:03:10.943 -> success
22:03:10.943 -> 0
22:03:10.943 -> 0.00
22:03:10.943 -> ⸮
22:03:10.943 -> Received 494 bytes in 0.3000ms, rate = 1.61 KB/sec
22:03:40.749 -> try www.arduino.cc connected IP 104.22.49.75
22:03:41.199 ->
22:03:41.199 -> client connected
22:03:41.199 -> HTTP/1.1 200 OK
22:03:41.199 -> status code=200
22:03:41.199 -> reason phrase=OK

22:03:41.199 -> Date: Tue, 27 Oct 2020 21:03:42 GMT
22:03:41.199 -> Content-Type: text/plain
22:03:41.199 -> Content-Length: 6
22:03:41.199 -> Connection: close
22:03:41.199 -> Last-Modified: Mon, 31 Aug 2020 09:25:41 GMT
22:03:41.199 -> ETag: "5f4cc215-6"
22:03:41.239 -> Accept-Ranges: bytes
22:03:41.239 -> CF-Cache-Status: DYNAMIC
22:03:41.239 -> cf-request-id: 060d78c64e00000d6398890000000001
22:03:41.239 -> Server: cloudflare
22:03:41.239 -> CF-RAY: 5e8f5d838ef70d63-VIE
22:03:41.239 ->
22:03:41.239 -> 10813
22:03:41.239 ->
22:03:41.239 -> body=
22:03:41.239 -> success
22:03:41.239 -> 0
22:03:41.239 -> 0.00
22:03:41.239 -> ⸮
22:03:41.279 -> Received 339 bytes in 0.3830ms, rate = 0.86 KB/sec

After a reset, when the Arduino hasn't a stored cookie - Arduino.cc will send a new cookie.

But it takes a lot of RAM (Arduino sends a 53 byte cookie), so you have to take care that you have enough global RAM available to store such long cookies.

I can't post the code today because it needs some cleanup and a malicious server could hang the client, but basically ... yes it can be done.

Thanks again for your guidance - I'm realising how little I know about this area and how much I have to learn to accomplish what I thought would be straight forward.

I knew in principle what I had to do but actually doing it and writing / debugging the code is a stretch for me when it comes to web based protocols.

I'd be interested to see your code and understand how it works and hopefully mould it to my requirements.

Understood about the risks and limitations etc.

Regards Tim

Repeating web client
this repeating web server does not only send data to the server but also

  • reads the server response
  • fetches the HTTP Status Code
  • reads the payload from the server

additionally,

  • there are two example functions how to parse a CSV and a Tag-Value Response from the payload
  • and finally, it also reads Set-Cookie and will use it for the next request.

post.txt (12.3 KB)

Thanks for this code, I will study and learn from it.
It looks easy to understand.

Regards Tim