You can use setcookie()
to set a cookie that contains the array of visited headers. This is a simple example to start with:
function header_cookies() {
// Check if any cookie is set
if(isset($_COOKIE[headers_visited])) {
$headers = $_COOKIE[headers_visited];
// Now add your headers to cookie and save it again. Let's remove the old one first
unset( $_COOKIE[headers_visited] );
// Store an array of headers here
$header_array;
// Now set the new cookie
setcookie( headers_visited, $header_array, time() +3600 /* For an hour */ );
// Return the array to use wherever you want
return $header_array;
} else {
// Set all the headers into an array
$header_array;
// Set the cookie
setcookie( headers_visited, $header_array, time() +3600 /* For an hour */ );
// Return the data
return $header_array;
}
}
// Run header_cookies() this when WordPress loads
add_action('init','header_cookies');
Now you have set the cookie, and have the array of set headers to use in your template.
Note that you need to use implode()
and explode()
to work with the arrays stored in the cookie.