PHP cookie removal with FF under cookie cannot delete _php tutorial

Source: Internet
Author: User
Tags setcookie
Set and delete cookies in PHP we use Setcookie to set them up and automatically delete them when they expire, but under FF you may encounter cookies that cannot expire.

First, let's take a look at the instructions in the PHP manual for deleting cookies.

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: Example 2. Setcookie () Delete
Example

The code is as follows Copy Code

Set the expiration time to one hour ago

Setcookie ("TestCookie", "", Time ()-3600);
Setcookie ("TestCookie", "", Time ()-3600, "/~rasmus/", ". utoronto.ca", 1);

Store the user's login information, and then use the

The code is as follows Copy Code

Setcookie ("username", "", Time ()-3600);

Do quit and test under IE without any problems. Since do the website, must be compatible with as many browsers, hehe. So in Firefox test, landing all normal, when launched, encountered trouble. How not to quit, the user is always logged in state. So I looked at the difference between the cookie records in IE and Firefox, and after testing, it dawned on me.

If you do not specify the fourth parameter of Setcookie () (The legal Path parameter), the current directory will be the default path, and the path I tested is: http://127.0.0.1/php/rss2fla/data/log.php, which results in login and exit The cookie path set is different.

IE more humane than Firefox, hehe, when the United States to specify the path, will overwrite the current IP under the same name cookie variable, and Firefox is more stringent, resulting in a re-built a variable ...

Take a look at some examples:

Simple:

The code is as follows Copy Code

Setcookie ("MyCookie", "Value of MyCookie");

With time of failure:

The code is as follows Copy Code

Setcookie ("Withexpire", "Expire in 1 Hour", Time () +3600);//3600 seconds = 1 hours

There are everything:

The code is as follows Copy Code

Setcookie ("Fullcookie", "full cookie value", Time () +3600, "/forum", ". bkjia.c0m", 1);

The last one is compatible with all browsers.

In summary, it is best to use the following method when working with cookies in PHP:

The code is as follows Copy Code
if (Isset ($_cookie["Sid"]) &&!empty ($_cookie["Sid"]) {
This ensures that the cookie is present and within the validity period
......
}

http://www.bkjia.com/PHPjc/632780.html www.bkjia.com true http://www.bkjia.com/PHPjc/632780.html techarticle set and delete cookies in PHP we use Setcookie to set them up and automatically delete them when they expire, but under FF you may encounter cookies that cannot expire. First we look at the PHP manual ...

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