I hope you can help me with a cookie. thank you!

Source: Internet
Author: User
A cookie problem. I hope you can help me. thank you. where is the error? PHPcode & lt ;? Phpif (empty ($ _ COOKIE [lastVisit]) {if it is empty, it is the first time you log on to echo & quot;. Hello, this is the first time you log on! & Quot; record the problem of setcooki cookie at the first logon time. I hope you can help me. thank you. where is the error?
PHP code
  
  

Error:
Hello, this is your first login!
Warning: Cannot modify header information-headers already sent by (output started at D: \ LAMP \ AppServ \ www \ cookie \ lastVisit. php: 4) in D: \ LAMP \ AppServ \ www \ cookie \ lastVisit. php on line 6


------ Solution --------------------
So change the code... In addition, if it is a UTF-8 encoded document, do not have a B header.

PHP code
$ First = FALSE; if (empty ($ _ COOKIE ['lastvisit']) {$ first = TRUE; setcookie ("lastVisit ", date ('Y-m-d H: I: s'), time () + 30*24*3600);} else {$ first = FALSE; setcookie ("lastVisit", date ('Y-m-d H: I: s'), time () + 30*24*3600);} if ($ first) {echo "Hello, this is your first logon! ";}Else {echo" your last access time was ". $ _ COOKIE ['lastvisit'];}
------ Solution --------------------
If there is output before the header, enable the buffer ob_start ();

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.