Establish a personal site for business sites or relatively complete, often need to record accessers, providing two convenient means in PHP: Session and cookie features. For permanent maintenance user information, Cookie is the most convenient means. Here I will explain the functions and methods of use of cookies in detail.
1: Setting cookies Before using cookies, you must set the cookie. Function prototype: int setCookie (String Name, String Value, int Expire, string path, string domain, int.com) where all parameters are optional, in addition to NAME, You can use an empty string that is not set. Properties Value: Used to specify the value. Properties path: Which of the directory paths used to specify cookies to the server. Properties Domain: You can limit the Send of cookies on the browser . EXPIRE parameter: Used to specify the valid time of the cookie, it is a standard UNIX time tag. You can get the Time () or mktime () function, in seconds. Secure Parameters: Indicates whether this cookie is encrypted by encrypted HTTPS protocol Transfer on the network.
2: Precautions when setting cookies In the same page, it is actually done in order from the previous order. If you want to delete a cookie, write a cookie, you must write a statement first. Write the delete statement. Otherwise, there will be an error. Three: SetCookie Example Simple: setCookie ("MyCookie", "Value_Of_MYCOOKIE"); Tetcookie ("WitHexpire", "Expire_1_Hour", Time () 3600); Everything: SetCookie ("FullCookie", "Full_cookie_Value", Time 3600, "/ Forum", "www.123.com", 1);
Four: Some features of the cookie are path-oriented. When the default Path property, the web server page will automatically pass the current path to the browser. Specify the path to force the server to use the settings. Cookies set in a directory page It is not seen in the page of a directory.