BrainPill Posted May 1, 2019 Share Posted May 1, 2019 I want to set a cookie in a proper way. So I want to add samesite strict. When I try to add it with : session_set_cookie_params() at the last parameter (6th) it says : Warning: session_set_cookie_params() expects at most 5 parameters, 6 given in example: <?php session_set_cookie_params(3600,'','',FALSE, TRUE,'strict'); ?> How can I add samesite in session_set_cookie_params() ? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 1, 2019 Share Posted May 1, 2019 Pass an array of options. https://www.php.net/manual/en/function.session-set-cookie-params.php Link to comment Share on other sites More sharing options...
BrainPill Posted May 2, 2019 Author Share Posted May 2, 2019 14 hours ago, justsomeguy said: Pass an array of options. https://www.php.net/manual/en/function.session-set-cookie-params.php I tried this: <?php $options = array('lifetime => 3600','samesite=>strict'); session_set_cookie_params($options); ?> but I get the following error: ( ! ) Notice: Array to string conversion in does this indicate that you have to read them out with foreach? The reason I ask this, is because all the other params could just be put into the session_set_cookie_params() function but this specific one not. This makes it an exception to the rule. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 2, 2019 Share Posted May 2, 2019 According to the notes in the manual, the options array was added in version 7.3. If you don't have that then you won't be able to use samesite for this. 1 Link to comment Share on other sites More sharing options...
Funce Posted May 2, 2019 Share Posted May 2, 2019 You array is not being properly defined as associative. Its currently an array with 2 elements of strings. You need to move the quotes. <?php $options = array( 'lifetime' => 3600, 'samesite' => 'strict' ); ?> Link to comment Share on other sites More sharing options...
BrainPill Posted May 6, 2019 Author Share Posted May 6, 2019 On 5/2/2019 at 11:24 PM, Funce said: You array is not being properly defined as associative. Its currently an array with 2 elements of strings. You need to move the quotes. <?php $options = array( 'lifetime' => 3600, 'samesite' => 'strict' ); ?> okay I fixed that now. But I the array to string error is still there. How to solve this? Link to comment Share on other sites More sharing options...
BrainPill Posted May 6, 2019 Author Share Posted May 6, 2019 On 5/2/2019 at 7:15 PM, justsomeguy said: According to the notes in the manual, the options array was added in version 7.3. If you don't have that then you won't be able to use samesite for this. I see that now. I have version 7.1.9 so it couldn't work. Link to comment Share on other sites More sharing options...
Funce Posted May 7, 2019 Share Posted May 7, 2019 Just had a look around. Would this be relevant? https://stackoverflow.com/questions/39750906/php-setcookie-samesite-strict Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now