H
H
hellcaster2018-03-12 20:05:33
PHP
hellcaster, 2018-03-12 20:05:33

How to make an array in $_COOKIE?

I have a piece of PHP code

$_SESSION["logged_user"] = $users_log_res; //$users_log_res это массив

And it turns out that $_SESSION["logged_user"] is an array. How to do this on a cookie? I write
setcookie( "logged_user", $users_log_res, time()+604800 );
and it tells me that:
Warning: setcookie() expects parameter 2 to be string, array given in W:\domains\blog.loc\header.php on line 57
Should this array be converted into a string?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-03-12
@web_Developer_Victor

Cookies can only contain a string. If array then json_encode do

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question