How can a session be associated with a cookie in PHP?

To associate a session with a cookie in PHP, you need to set the session cookie parameters before starting the session. This can be done by using the session_set_cookie_params() function to set the parameters such as the cookie lifetime, path, domain, secure flag, and httponly flag. By setting these parameters, the session will be associated with a cookie that will be sent to the client's browser.

// Set the session cookie parameters
session_set_cookie_params(86400, '/', '.example.com', true, true);

// Start the session
session_start();