V
V
vitaliyharchenko2014-07-25 14:10:58
PHP
vitaliyharchenko, 2014-07-25 14:10:58

Why is the value of the variable not being injected into the cookie (PHP)?

I make a POST request to the server, I get a response like:
{"response": {"user_id": "88"}}
Next, parse the response:

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

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

But cookies are not set.
If you set $user_id manually, for example:
$user_id = "2";
then the value is entered into the cookie
. If done
$user_id = (integer) $user_id;
, then the value 0 is entered, that is, the problem is in the type of the variable
var_dump($user_id) shows string, as in the setcookie specification.
Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2014-07-25
@Dimitriys

$userid = $response["user_id"];
replace it with
something :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question