Php cookie demo


What is a Cookie?

A cookie is often used to lớn identify a user. A cookie is a small file that the VPS embeds on the user"s computer. Each time the same computer requests a page with a browser, it will skết thúc the cookie too. With PHP.., you can both create & retrieve sầu cookie values.

Bạn đang xem: Php cookie demo

Create Cookies With PHP

A cookie is created with the setcookie() function.

Syntax



Only the name parameter is required. All other parameters are optional.

Xem thêm: Giới Thiệu Về Groovy Là Gì ? Nghĩa Của Từ Groovy Trong Tiếng Việt

PHPhường Create/Retrieve a Cookie

The following example creates a cookie named "user" with the value "John Doe". The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire trang web (otherwise, select the directory you prefer).

We then retrieve sầu the value of the cookie "user" (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set:



)) else ?>


Note: The value of the cookie is automatically URLencoded when sending the cookie, & automatically decoded when received (to lớn prsự kiện URLencoding, use setrawcookie() instead).


Modify a Cookie Value

To modify a cookie, just mix (again) the cookie using the setcookie() function:



)) else ?>

Delete a Cookie

To delete a cookie, use the setcookie() function with an expiration date in the past:





Cheông chồng if Cookies are Enabled

The following example creates a small script that checks whether cookies are enabled. First, try to lớn create a demo cookie with the setcookie() function, then count the $_COOKIE array variable:



0) else ?>

Complete PHPhường Network Reference

For a complete reference of Network functions, go to lớn our complete PHP. Network Reference.

PHPhường Exercises

Test Yourself With Exercises


×

Report Error

If you want lớn report an error, or if you want khổng lồ make a suggestion, do not hesitate khổng lồ send us an e-mail:

help


Top Tutorials HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Pybé nhỏ Tutorial W3.CSS Tutorial Bootstrap Tutorial PHPhường. Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top References HTML Reference CSS Reference JavaScript Reference SQL Reference Pyeo hẹp Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference Angular Reference jQuery Reference
Top Examples HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Pyhạn hẹp Examples W3.CSS Examples Bootstrap Examples PHP. Examples Java Examples XML Examples jQuery Examples
Web Courses HTML Course CSS Course JavaScript Course Front End Course SQL Course Pybé Course PHPhường Course jQuery Course Java Course C++ Course C# Course XML Course Get Certified »
obatambeienwasirherbal.com is optimized for learning và training. Examples might be simplified lớn improve reading và learning. Tutorials, references, & examples are constantly reviewed lớn avoid errors, but we cannot warrant full correctness of all content. While using obatambeienwasirherbal.com, you agree lớn have read and accepted our terms of use, cookie và privacy policy. Copyright 1999-2021 by Refsnes Data. All Rights Reserved. obatambeienwasirherbal.com is Powered by W3.CSS.

*