When does PHP set the session cookie?

Viewed 166

I have some difficulties maintaining session on server request and response between initial server call and ajax call.

I am sending an ajax call after the server initial load to the same domain where am using sessions in both cases

The session cookie is not being set on server load (knowing that session_start() is called and the session has data) and it seems that it is being set twice on first ajax call:

Server Response of ajax call after page load

Set-Cookie: PHPSESSID=aef6668de2af148bcc3a3bd3de71f880; expires=Tue, 08-Mar-2016 07:38:43 GMT; path=/; domain=www.somedomain.com; secure; HttpOnly PHPSESSID=aef6668de2af148bcc3a3bd3de71f880; expires=Tue, 08-Mar-2016 07:38:43 GMT; path=/

What actually triggers the server to send Set-Cookie header setting the session in cookie on server response?

Is it the session_start() or setting the $_SESSION with a given value at server side?

I know that session_set_cookie_params() also has this impact but can this in anyway create 2 consecutive set calls of the session if session_set_cookie_params() is called with session_start() in the same server response ?

0 Answers
Related