Why is my cookie unusable? and PHP must be written in this way?
This is the first two days according to a piece of code written in the book, the note is written by myself, I am in the following login.php page login, unable to obtain a cookie, but I login.php on the front of the page with Echo $_post["username"] But can get to the value from the table only son, do not know that I cookiemanager this class is wrong, or what went wrong?
Novice, the use of custom functions is not very clear, and then ask everyone in PHP used to write the main code in a separate page, and then load it into use? Maybe the problem is a little white, but this is an important step in getting familiar with PHP ·
PHP Code
$value) { Setcookie ($key, $value); } } Public Function Set_cookie ($key, $value) { //Set Setcookie ($key, $value); } Public Function Get_array_cookie () { return $_cookie; } Public Function Up_cookie ($key, $value) { Setcookie ($key, "", $time);} } Global $cm; if (!isset ($cm)) { $cm =new cookiemanager (); Determine if a $cm variable exists, and the instantiation is not present}?>
PHP Code
Get_cookiev ("username")) { echo <<
<>
Username
Password
EOT;} else{ Print_r ($cm->get_array_cookie ()); Echo '
Exit ';} Ob_flush ();? >
------Solution--------------------
PHP code
!--? phpclass cookiemanager{public Function Get_c Ookiev ($key) {//Get COOKIE return $_cookie[$key]; } Public Function Set_array_cookie ($ARRYC) {//Gets the Cookie array loop foreach ($arryc as $key =--> $value) {Set Cookies ($key, $value); }} Public Function Set_cookie ($key, $value) {//Set Setcookie ($key, $value); } public Function Get_array_cookie () {return $_cookie; The Public Function Up_cookie ($key, $value) {Setcookie ($key, "", $time); }}?>