I am having an issue after I unset a cookie in php. This is my code
controller.php
setcookie("alert",'String',time()+3600,'/');
header("Location: ../home.php");
home.php
if(!empty($_COOKIE['alert']) && $_COOKIE['alert'] != ''){
malert($_COOKIE['alert']);
$_COOKIE['alert'] = '';
setcookie('alert', '', time()-1000);
setcookie('alert', '', time()-1000, '/');
print_r($_COOKIE);
}
When the home page loads the function malert works. But I expect it to skip the if condition when the page is refreshed again.. The problem is even after refreshing the home.php again , it is entering the if condition. Am i missing any information here on page refresh about cookie.?
The print_r output is
Array ( [PHPSESSID] => xxx [alert] => String )
Array ( [PHPSESSID] => xxx [alert] => )
Note: As I am using .htpassword in this folder I am not able to use SESSION
You’re calling setcookie() after print_r(). You can’t call setcookie() after outputting content because headers are already sent.