Monday, February 14, 2011

To delete cookies in PHP

A cookie is a text in the browser cache file.

Its purpose is to store the browser to create the right environment for the user information. Cookies are used to link information to store information session and wagons in e-commerce sites. Cookies are automatically deleted when the browser is closed, but sometimes to delete the cookie before the browser is closed. And sometimes it must longer. PHP can be used to perform these two tasks.

    Creating cookies
  1. The command is a PHP to create cookie is "Setcookie (name, value);" where is the name of the cookie and value is the information stored in the cookie.
For example, setcookie ('favorite cookies ',' chocolate chip') create a cookie with preferred name with a value of chocolate chip cookies. Obviously, the names and values determined ultimately as the cookie is used by the server.

Deleting cookies
  • Sometimes you want to delete cookies, before a user its browser, such as closes when you make a connection.
  • To remove a cookie, remove only their value. PHP code is setcookie(name,_'') or setcookie (name, FALSE). To remove the favorite cookies from the previous example is code setcookie ('Favorite Cookies' ') or setcookie ('favorite cookies', FALSE). It is important to note, that not treat other arguments cookies here take these arguments are also included, must if to delete a cookie. For example, if the cookie in this way was created: setcookie ("Favorite Cookies", "chocolate chip", time () + 3600, ", 'www.ehow.com', 1") all this parameters must be present minus the value of the cookie: setcookie ('fav)orite cookies' ", time () (+ 3600 ', 'www.ehow.com', 1)."

    Keep cookies
  • Where you the cookie to last, that the browser would b
  • Een closed, you must declare that when the cookie is created. Use of "time () + X" argument, where X is equal to the number of seconds that the cookie should exist after it is created. The cookie "Preferred Cookies" create, lasted one hour after the creation, the code example, setcookie ("Favorite Cookies", "chocolate chip", time () + 3600). Time()-Funktion function checks the current time and computes the 3600 seconds from now (one hour in seconds). If the time is reached, the cookie is deleted when the user nor the browser or does not use.

    No comments:

    Post a Comment