Click here to Skip to main content
15,895,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
values is javascript variable. I taken javascript variable value in php variable. After taking value i want to clear cookie.
document.cookie = "values = " + values;
$pst_strength_weakness1= $_COOKIE['values'];

What I have tried:

i dont know how to clear cookie
Posted
Updated 28-Feb-21 20:14pm

1 solution

Take a look here: How to Create, Read, Update and Delete Cookies with PHP or Javascript - pontikis.net[^]

Quote:
Actually, there is not a way to directly delete a cookie. Just use setcookie with expiration date in the past, to trigger the removal mechanism in your browser.

PHP
$cookie_name = 'pontikis_net_php_cookie';
unset($_COOKIE[$cookie_name]);
// empty value and expiration one hour before
$res = setcookie($cookie_name, '', time() - 3600);


The same is stated here: PHP Cookies[^] but with less words.
 
Share this answer
 
v2
Comments
Member 15086478 1-Mar-21 4:27am    
using unset(), cookie value will not get removed
Maciej Los 1-Mar-21 4:53am    
Please, read my answer carefully. You CAN'T remove cookie. You can "clear" its content, where "clear" means set cookie as expired.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900