Why value variable is not included in the cookie (PHP)?

Make a POST request to the server, receive a response of the form:
{"response": {"user_id": "88"}}

Further respark response:
$obj = json_decode($result, true);
$response = $obj["response"];
$userid = $response["user_id"];

And set cookies
setcookie("user_id", $user_id, time() + 3600, '/');

But cookie not set.

If you set $user_id manually, for example:
$user_id = "2";
the value in the cookie is stored

If you do
$user_id = (integer) $user_id;

it takes on the value 0, then there is a problem in the type of a variable

var_dump($user_id) shows a string, as in the specification setcookie.

What is the error?
September 26th 19 at 11:41
1 answer
September 26th 19 at 11:43
$userid = $response["user_id"];
$user_id = $response["user_id"];
nezachto :)
Thank you, quite, open-minded) - heber_Erdman commented on September 26th 19 at 11:46

Find more questions by tags HTTP CookiesPHP