开发者

PHP - session_set_cookie_params and session_get_cookie_params

开发者 https://www.devze.com 2022-12-27 04:09 出处:网络
im looking into sessions a bit more and would like some input. on a simple login form once the form is submited i have the following

im looking into sessions a bit more and would like some input.

on a simple login form once the form is submited i have the following

.
..
...
session_name('TOKEN');
session_set_cookie_params( time() + 600, './', 'example.co.uk', false, false);
session_start();
$_SESSION['TOKEN'] = TOKEN;
...
..
. 

and then when a request to the server is made I have this.

.
..
...
session_name('TOKEN');
$session_data = session_get_cookie_params();
print_r($session_data);
...
..
. 

which returns Array ( [lifetime] => 0 [path] => / [domain] => [secure] => [httponly] => )

as you can see something is not working or I am missing something or im go开发者_如何学Cing a little potty!

anyway, If anyone has any input on where im going wrong i would love to here it!


You may have figured it out already, but session_set_cookie_params() needs to be called before session_start() for every single page request. So sayth the manual entry for the function.


the best solution is not to touch session cookie params at all
sessions works pretty fine with default values. and with manual correction you'd make it worst.

as for your question, session_get_cookie_params works fine. it shows you current settings which don't seem to be altered in this another file.


i think it may work

session_set_cookie_params( time() + 600, '/', '.example.co.uk', false, false);

'/' not './'

'.example.co.uk' not 'example.co.uk'

this worked fine for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消