Skip to content
Advertisement

session_set_cookie_params array to string conversion

When I try to set some cookie parameters in PHP using the session_set_cookie_params function, I get an error stating that I’m trying to convert an array to a string.

This is my code:

$cookie_params             = session_get_cookie_params();
$cookie_params['secure']   = true;
$cookie_params['samesite'] = "None";

session_set_cookie_params($cookie_params);

Any clue why this is happening?

Advertisement

Answer

Since version 7.3 of PHP the session_set_cookie_params function accepts an array of options, including the samesite attribute. I was mixing some versions of PHP. Apparently my development environment changed the version of PHP it used to 7.0.33

If you’re encountering this error, make sure both are at least 7.3, that will fix your error.

Documentation on the function

Note:

Yes, I answered my own question, but searching online in the way I am used to didn’t quickly return any results that resolved my problem, which is why I choose to ask and answer my question (something StackOverflow allows you to do).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement