How do i create a cookie that will hide a section on my page when the cookie is set and show the section when the cookie deleted?
Printable View
How do i create a cookie that will hide a section on my page when the cookie is set and show the section when the cookie deleted?
Use ifs and elses...
Yeah, just do this:Hope that explains it ;)PHP Code:<?php
if (isset($_COOKIE['cookiename'])) {
// what you want to have if cookie is set
} else {
// what you want to have if cookie is not set
}
?>
Then to set the cookie...
$coo = setcookie("cookiename","value",time()+expire time,"/","domain");
if (!$coo) {echo "Failed";} else {echo "Successful";}
* expires in- 3600*12 = 12 hours, 3600*24*7 = 7 days, 3600*24*365 = 365 days
* Domain - your web address: www.domain.com