forms - PHP Cookie Issue -
this question has answer here:
- why cookies not setting? 4 answers
i trying create html form username, name, , email address , php store username cookie. then, store username, name, , email address.
then, when log go form again, form greet user cookie information. unsure how proceed, if can give me suggestions. thanks!
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> <form action = "userinfo.php" method = "post"> username:<br> <input type="text" name="username"> <br> fullname:<br> <input type="text" name="fullname"> <br> email:<br> <input type="text" name="email"> <br> <input type="submit" value="submit"> </form> </head> <body> </body> </html> <?php session_start(); $cookie_name = "user"; $cookie_value = "username"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day if (!isset($_cookie[$cookie_name])) { echo "cookie named '" . $cookie_name . "' not set!"; } else { echo "cookie '" . $cookie_name . "' set!<br>"; echo "value is: " . $_cookie[$cookie_name]; } ?>
php superglobal ($_get, $_post, $_server, $_cookie, etc...) set once when script first starts up, , never changed again php.
whatever cookies create setcookie() appear in $_cookie on next script execution.
the sole exception $_session, gets populated after session_start() called.
Comments
Post a Comment