I know that when use setcookie()
function it create headers, and after refresh it will be available in $_COOKIES
, but i need a mechanism to set cookie in this page without redirect, but to be in the browser cookie. If make something like this
setcookie('my_cookie','tmp_val');
$_COOKIE['my_cookie'] = 'tmp_val;
It is good for case when you set at once, but when you set cookie on each refresh in PHP is good but in browser cookie remains old. I try something like this
add_action('parse_request', function($tmp){
setcookie('my_cookie','tmp_val');
wp_safe_redirect(get_permalink());
exit();
});
but I have problems. Please help me in order to find a good solution.