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?

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.