tailieunhanh - PHP 5 Recipes A Problem-Solution Approach PHẦN 8

Khi một đối tượng mới RegExp được tạo ra, mô hình được giữ bên trong các đối tượng sử dụng trong các trận đấu và thay thế trong tương lai của nó. lớpBởi vì các thuộc tính sẽ được tự động tạo ra, bạn có thể làm giảm ví dụ này một chút mà không ảnh hưởng đến kết quả. | 454 12-1 SETTING COOKIES 12-1. Setting Cookies To be able to use cookies and store values in them you must first set a cookie on a user s computer. You can use plenty of parameters to take full advantage of a cookie including the expiration time path of use name value and so on. By using the different parameters you can customize the way the cookie works for you. The way to set a cookie is by using the function setcookie which has the following prototype bool setcookie string name string value int expire string path string domain bool secure Table 12-1 lists the parameters available to you when creating a cookie using setcookie . Table 12-1. PHP5 setcookie Parameters Parameter Description name The name to set the cookie variable to and hence the name to access it with value The value of the current cookie expire When a cookie will expire in the form of a Unix timestamp path The directory where the cookie will be available for use domain The domain at which the cookie will be available secure Whether a cookie can be read on a non-SSL enable script The Code php Let s say that the correct login is based on these global user and pass values. In the real world this would be taken from the database most likely. GLOBALS username test GLOBALS password test Here is an example to set a cookie based on a correct login. function validatelogin username password Check for a valid match. if strcmp username GLOBALS username 0 strcmp password GLOBALS password 0 If you have a valid match then you set the cookies. This will set two cookies one named cookie_user set to cookieuser and another set to cookie_pass which contains the value of password. When storing passwords it is a good idea to use something like md5 to encrypt the stored cookie. setcookie cookie_user username time 60 60 24 30 setcookie cookie_pass md5 password time 60 60 24 30 return true else 12-2 READING COOKIES 455 return false You call the validatelogin script. if validatelogin test test echo .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.