Hướng dẫn explain the process of setting and deleting cookies in php - giải thích quá trình thiết lập và xóa cookie trong php

Cookie trong PHP là một tệp nhỏ với kích thước tối đa 4kb mà máy chủ web lưu trữ trên máy khách. Chúng thường được sử dụng để theo dõi thông tin như tên người dùng mà trang web có thể truy xuất để cá nhân hóa trang khi người dùng truy cập trang web vào lần tới. Một cookie chỉ có thể được đọc từ miền mà nó đã được phát hành. Cookie thường được đặt trong tiêu đề HTTP nhưng JavaScript cũng có thể đặt cookie trực tiếp trên trình duyệt.cookie in PHP is a small file with a maximum size of 4KB that the web server stores on the client computer. They are typically used to keep track of information such as a username that the site can retrieve to personalize the page when the user visits the website next time. A cookie can only be read from the domain that it has been issued from. Cookies are usually set in an HTTP header but JavaScript can also set a cookie directly on a browser.

Đặt cookie trong PHP: Để đặt cookie trong PHP, hàm setCookie [] được sử dụng. Hàm setCookie [] cần được gọi trước bất kỳ đầu ra nào được tạo bởi tập lệnh nếu không cookie sẽ không được đặt.: To set a cookie in PHP, the setcookie[] function is used. The setcookie[] function needs to be called prior to any output generated by the script otherwise the cookie will not be set.

Syntax:

setcookie[name, value, expire, path, domain, security];

Tham số: hàm setCookie [] yêu cầu sáu đối số nói chung là: & nbsp; The setcookie[] function requires six arguments in general which are: 

  • Tên: Nó được sử dụng để đặt tên của cookie.It is used to set the name of the cookie.
  • Giá trị: Nó được sử dụng để đặt giá trị của cookie.It is used to set the value of the cookie.
  • Hết hạn: Nó được sử dụng để đặt dấu thời gian hết hạn của cookie sau đó cookie có thể được truy cập.It is used to set the expiry timestamp of the cookie after which the cookie can’t be accessed.
  • Đường dẫn: Nó được sử dụng để chỉ định đường dẫn trên máy chủ mà cookie sẽ có sẵn.It is used to specify the path on the server for which the cookie will be available.
  • Tên miền: Nó được sử dụng để chỉ định miền mà cookie có sẵn.It is used to specify the domain for which the cookie is available.
  • Bảo mật: Nó được sử dụng để chỉ ra rằng cookie chỉ nên được gửi nếu kết nối HTTPS an toàn tồn tại.It is used to indicate that the cookie should be sent only if a secure HTTPS connection exists.

Dưới đây là một số hoạt động có thể được thực hiện trên cookie trong PHP:

  • Tạo cookie: Tạo một cookie có tên Auction_Item và gán giá trị xe sang trọng cho nó. Cookie sẽ hết hạn sau 2 ngày [2 ngày * 24 giờ * 60 phút * 60 giây].: Creating a cookie named Auction_Item and assigning the value Luxury Car to it. The cookie will expire after 2 days[2 days * 24 hours * 60 mins * 60 seconds].

Ví dụ: Ví dụ này mô tả việc tạo cookie trong PHP.This example describes the creation of the cookie in PHP.

PHP

0

1

    

    

0

1

    

    

Bài Viết Liên Quan

Chủ Đề