PHP hỗ trợ cookie HTTP một cách minh bạch. Cookie là cơ chế lưu trữ dữ liệu trong trình duyệt từ xa và do đó theo dõi hoặc xác định người dùng cũ. Bạn có thể đặt cookie bằng hàm setcookie[] hoặc setrawcookie[]. Cookie là một phần của tiêu đề HTTP, vì vậy setcookie[] phải được gọi trước khi bất kỳ đầu ra nào được gửi tới trình duyệt. Đây là hạn chế tương tự mà header[] có. Bạn có thể sử dụng các chức năng đệm đầu ra để trì hoãn đầu ra tập lệnh cho đến khi bạn quyết định có đặt bất kỳ cookie nào hoặc gửi bất kỳ tiêu đề nào hay không
Bất kỳ cookie nào được gửi đến máy chủ từ máy khách sẽ tự động được đưa vào mảng tự động toàn cục $_COOKIE nếu chứa "C". Nếu bạn muốn gán nhiều giá trị cho một cookie, chỉ cần thêm []
vào tên cookie
Để biết thêm chi tiết, bao gồm ghi chú về lỗi trình duyệt, hãy xem hàm setcookie[] và setrawcookie[]
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
Just a general comment on Wilton's code snippet: It's generally considered very bad practice to store usernames and/or passwords in cookies, whether or not they're obsfucated. Many spyware programs make a point of stealing cookie contents.
A much better solution would be to either use the PHP built in session handler or create something similar using your own cookie-based session ID. This session ID could be tied to the source IP address or can be timed out as required but since the ID can be expired separately from the authentication criteria the authentication itself is not compromised.
Stuart Livings
It's important to set htttponly to true to prevent XSS Attacks.
Also you could prevent user from changing the value to prevent getting another user data.
Isso:
unset[$_COOKIE["cookie"]];
?>
________số 8
$_COOKIE["cookie"] = "foo bar";
?>
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
0
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
1
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
2
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
3
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
4
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
5
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
6
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
7
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
8
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
2
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
3
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
4
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
5
Just a general comment on Wilton's code snippet: It's generally considered very bad practice to store usernames and/or passwords in cookies, whether or not they're obsfucated. Many spyware programs make a point of stealing cookie contents.
3
Just a general comment on Wilton's code snippet: It's generally considered very bad practice to store usernames and/or passwords in cookies, whether or not they're obsfucated. Many spyware programs make a point of stealing cookie contents.
4
Just a general comment on Wilton's code snippet: It's generally considered very bad practice to store usernames and/or passwords in cookies, whether or not they're obsfucated. Many spyware programs make a point of stealing cookie contents.
5