PHP Cookies are not being set -
PHP Cookies are not being set -
i'm having issues setting cookies. problem cookies aren't beingness set, have setup test below see if beingness set never beingness set. i've checked in browser see if beingness set, nil site.
i help me create cookies set. i'm not quite sure do. give thanks you.
here code:
<?php session_start(); setcookie("ridarray","", time()+3600); if (isset($_cookie['ridarray'])) { echo "ridarray set."; } ?> <head> </head> <html> <body> <?php if (isset($_cookie['ridarray'])) { echo "ridarray set."; } else { echo "not set"; } ?> </body> </html>
here's problem, setcookie documentation:
cookies must deleted same parameters set with. if value argument empty string, or false, , other arguments match previous phone call setcookie, cookie specified name deleted remote client. internally achieved setting value 'deleted' , expiration time 1 year in past.
you setting cookie value empty string (""). try:
setcookie("ridarray","not blank value", time()+3600);
the other issue when set cookie, not in request headers (accessed via $_cookie) until next page load. means when load page first time, $_cookie['ridarray'] not set. on subsequent loads, set, , reset every time.
first page load, won't set. refresh, , set.
the easiest way debug cookies utilize chrome's developer tools or firefox's firebug , watch response headers setcookie header, , request headers see cookies browser sending.
php cookies setcookie
Comments
Post a Comment