Php $ _ COOKIE simple application instance

Source: Internet
Author: User
Cookie is the information sent before the webpage content is sent. that is to say, no html code or echo can be found before the cookie is sent. even a space is not allowed in

Cookie is the information sent before the webpage content is sent. that is to say, there cannot be any html code or echo before this, and even a space is not allowed.

In php, you need to use the setcookie function to register the cookie variable. your code above does not register the cookie variable. how can it be sent? the correct syntax is as follows:

  1. */
  2. $ Status = 0; // define the status
  3. If (isset ($ _ cookie ['mytacky ']) & ($ _ cookie ['mytacky'] = "chocchip") $ status = 1; // if the variable has been set
  4. If (! Isset ($ _ get ['cchk']) // if no variable is set
  5. {
  6. Setcookie ("mytstcky", "chocchip"); // send cookie information
  7. Header ("location: $ php_self? Cchk = 1 "); // send the header
  8. Exit; // end the php code
  9. }
  10. ?>
  11.  
  12. Cookie check 
  13. Cookie check status:
  14. Printf ('% s
    ; ', $ Status? "00ff00": "ff0000", $ status? "Passed! ":" Failed! "); // Output different content according to the condition
  15. ?>
  16.  
  17.  

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.