PHP cookie does not guarantee workaround _php Tutorial

Source: Internet
Author: User
Tags setcookie
Cookies exist on the client side, not related to the server, note the case of your program, Linux is case-sensitive, and the configuration of the PHP tutorial, such as whether register_globals = OFF configuration on both sides of the same and so on.

The meaning of the @ and # symbols of PHP

function foo ($n)
{
$result = 1/$n;
return $result;
}
echo @foo (0); A 0 error is generated in the function, but the error is not displayed when the @ is added.
echo "End"; Output end
# comment Symbols

As with//, # is a single-line comment (Multi-line Comment */* */).

Because of the use of @setcookie, even if the cookie is written in error, it will not output, resulting in the problem can not be detected. Finally, the @setcookie changed to Setcookie, the program output the following error message:

Warning:cannot Modify header Information-headers already sent by (output started at

After a search on the internet, found that the original in the Setcookie Setup can not have any output content, and then go to check the code, also did not find out in Setcookie before the output of things, in a bit, found the problem, the specific content as follows:

Today in the WordPress Chinese forum stroll around. The jar is not very popular, but there are a lot of good masters. Will write plug-ins and templates of the master and even edit files will not be mixed with beginners, the forum is so, haha.

See the same error in several posts, such as the one mentioned in this post: "Warning:cannot Modify header Information-headers already sent by (output started at c:progr Am fileseasyphp1-8wwwwp-config.php:1) in C:Program fileseasyphp1-8wwwwp-login.php on line 9 "

This is a very typical problem. WordPress program execution will first call the Wp-config.php class of configuration files, will also call wp-db.php to establish a database tutorial connection for later use. These files just do some setup and do not output HTML code. After the setup is finished, the program itself starts executing, and some programs use the header command to set an HTTP header. Because the HTTP header must be set before the HTML code output, otherwise the HTML code has already started to send to the client, HTTP has already been sent, cannot chase back to reset. WordPress Codex The question: How does I solve the Headers already sent warning? The article states: to ensure that each file-especially the wp-config.php file that is often edited- ends with no other characters. Specifically to the above example, it is clear that the first line of wp-config.php is the beginning of the HTML output, which may be the first line of

Workaround

WordPress Chinese Forum does not provide full-text search function, can only search the title, so I used Google to search for a bit cannot modify header information site:wordpress.org.cn, as if encountered this problem is really a lot of people. At present, we use WordPress is mainly wordpress English original and a few WordPress Chinese version. My Chinese bag does not contain wp-config-sample.php file, nature is not my business; The original version of the ASCII code used in WordPress, naturally does not include the BOM, will not make such a mistake; Xigang made in WordPress Chinese forum in the WordPress Chinese forums have under, I go to download The WordPress 2.0.4 and 2.0.3 These two, check a bit, no problem; Click on the WordPress 2.0.4 Chinese version, wp-config-sample.php file with GB2312 code and DOS line tail, god! but this is good , if someone uses Notepad to modify this file, Dos line-end character does not cause editing problems, GB2312 encoding does not cause BOM problems


Cookie usage
Instructions for deleting a cookie start-----

BOOL Setcookie (string name [, string value [, int expire [, String path [, string domain [, bool secure]]])

To delete a cookie, you need to ensure that its expiration period is in the past before it triggers the browser's removal mechanism.

The following example shows how to delete a cookie that you just set:
Set the expiration time to one hour ago
Setcookie ("TestCookie", "", Time ()-3600);
Setcookie ("TestCookie", "", Time ()-3600, "/~rasmus/", ". utoronto.ca", 1);
?>


-----The end of the instructions for deleting cookies-----

The way to delete a cookie is to set the cookie's validity period to the current time, which is what almost any PHP programmer would do.

Later, a friend of my first contact with PHP told me that in the program he had wanted to set the value of a cookie to null, resulting in the cookie being deleted directly. My first reaction was not to believe, so the test
A moment:
Setcookie ("TestCookie", "');
Print_r ($_cookie);


The result is that the entire $_cookie array is empty, not just $_cookie[' TestCookie '). So with Winsock grab packet, observe the return HTTP header, found HTTP header unexpectedly is "set-cookie:testcookie=deleted;" Expires=mon, 18-jun-2007 02:42:33 GMT ", which shows" Setcookie ("TestCookie", "');" It is true that TestCookie is deleted directly from the cookie, which is completely not explained in the PHP manual.

http://www.bkjia.com/PHPjc/632283.html www.bkjia.com true http://www.bkjia.com/PHPjc/632283.html techarticle cookies exist on the client side, not related to the server, note the case of your program, Linux is case-sensitive, and the PHP tutorial configuration, such as whether register_globals = of ...

  • 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.