Jump to content

session_set_cookie_params not overwriting php.ini parameter


tork

Recommended Posts

Here are my relevant php.ini settings:

 

session.name = hello

session.cookie_lifetime = 30

session.cookie_path = /

session.cookie_domain = .name.com

 

And my script:

 

session_start();
setcookie('hello', '', time(), '/', '.name.com');

 

The php.ini value works as expected with the cookie being created and then timing out after 30 seconds - confirmed in Firebug under 'Cookies'.

 

Then I add the session_set_cookie_params statement with 75 second expiry:

 

session_set_cookie_params(75, '/', '.name.com');

session_start();
setcookie('hello', '', time(), '/', '.name.com');

 

When I look at the Cookies tab in Firebug, no cookie shows up. Now I reckoned that the session_set_cookie_params 75 seconds would overwrite the php.ini session.cookie_lifetime value of 30 seconds, and the setcookie create a cookie timed to expire 75 seconds later, yet they seem not to. 

 

Why is this?

 

 

 

the session.cookie_* settings only affect the PHP session cookie that is created with the session_start() function. Those settings have no effect on cookies set using setcookie()

 

This

setcookie('hello', '', time(), '/', '.name.com');

sets a cookie called hello and is immediately expired. To make it expire 75 seconds later you need to set the expire time param to time()+75

 

session_set_cookie_params do override the default settings defined in the php.ini. You should be able to verify this using session_get_cookie_params before and after changing the cookie params.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.