Expiring cookies in PHP

Expiring cookies

In PHP, you can expire cookies by setting their expiration time to a value in the past. Here’s an example of how to expire a cookie in PHP:

// Expire the "username" cookie
setcookie("username", "", time() - 3600, "/");

In this example, the setcookie() function is used to set the value of the “username” cookie to an empty string, an expiration time of one hour in the past, and a path of “/”. This causes the browser to remove the cookie.

Note that cookies can only be accessed on subsequent requests, so you may need to refresh the page or navigate to a new page to see the effects of expiring a cookie. Additionally, cookies can only be accessed on the same domain that set them, so you can’t expire a cookie on one domain and expect it to be removed on another.

Apply for PHP Certification!

https://www.vskills.in/certification/certified-php-developer

Back to Tutorials

Share this post
[social_warfare]
Generating the DataContext
Configuring the LinqDataSource

Get industry recognized certification – Contact us

keyboard_arrow_up