Why is my cookie so unusable? And does PHP have to be written in this way?

Source: Internet
Author: User
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); }}?> 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.