how to delete all cookies of my website in php
PHP setcookie()
Taken from that page, this will unset all of the cookies for your domain:
// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
http://www.php.net/manual/en/function.setcookie.php#73484
How to delete all the cookies of the browser in php
You can't.
For obvious security reasons. You can't read (and delete) cookies that belongs to another domain. If you could, than all website would have access to all cookies in your computer.
How can I delete all of my users' cookies for my website?
In this cases that we set cookie in the client side, we can set a code in the first lines of our application and remove that coockie like this:
In JavaScript:
document.cookie = NAME + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
Or in PHP:
if (isset($_COOKIE['NAME'])) {
unset($_COOKIE['NAME']);
setcookie('NAME', null, -1, '/');
}
With this approach all users that visit your website again its cookie expires.
You can delete all cookies in PHP. please follow how to delete all cookies of my website in php also for JavaScript How can I delete all cookies with JavaScript?
Remove a cookie
You May Try this
if (isset($_COOKIE['remember_user'])) {
unset($_COOKIE['remember_user']);
setcookie('remember_user', null, -1, '/');
return true;
} else {
return false;
}
How to delete all cookies with the same name?
No not all at once. If you want remove the specific cookies you need to use the cookie name. If you want to unset all cookies you can use this:
// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
This is a function that is published on http://php.net/manual/en/function.setcookie.php#Hcom73484
Related Topics
Mongodb Duplicate Documents Even After Adding Unique Key
Compare Multiple Values in PHP
How to Run a PHP Script Inside a HTML File
Fatal Error: Call to a Member Function Prepare() on Null
How to Replace Text Urls and Exclude Urls in HTML Tags
PHP Expression ≪≪≪Eob
How to Re-Index the Values of an Array in PHP
Laravel 5 Failed Opening Required Bootstrap/../Vendor/Autoload.PHP
Characters Allowed in PHP Array Keys
How to Remove a Variable from a PHP Session Array
How to Strip Trailing Zeros in PHP
PHP Getting Domain Name from Subdomain
PHP Redirection With Post Parameters
Debugging PHP Mail() And/Or PHPmailer
Why I'M Getting 500 Error When Using File_Get_Contents(), But Works in a Browser