Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - session_set_cookie_params and session_get_cookie_params

Tags:

php

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 going a little potty!

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

like image 522
Phil Jackson Avatar asked Jul 25 '26 02:07

Phil Jackson


1 Answers

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.

like image 54
Reuben Avatar answered Jul 26 '26 16:07

Reuben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!