PHP Accessing cookie value in html page using jquery+ajax -
i'm trying access cookie value html using jquery or ajax ,i'm new ajax don't know how access json
values. tried $.getjson()
not working. when execute same code localhost
, showing john
.
test.php
<?php $cookie_name = "user"; $cookie_value = "john"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); echo json_encode($_cookie[$cookie_name]); ?>
not sure how planning on using value on client side, issue why not getting output fourth parameter option have in setcookie()
function. i'm not sure why have documentation found not list fourth option. function accepts name, value, , time live.
also, if want return name of user value, don't need use json_encode(). can echo name response:
<?php $cookie_name = "user"; $cookie_value = "john"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30)); echo $_cookie[$cookie_name]; ?>
Comments
Post a Comment