I have set a cookie in my functions.php as follows:
add_action('send_headers', 'sfdc_cookie');
function sfdc_cookie() {
if( isset($_GET['sfdc']) && '' != $_GET['sfdc'] ) {
if( empty($_COOKIE['sfdc']) ){
if ($_GET['sfdc'] == 'mim'):
setcookie('sfdc', 'cookievalue', time()+3156000, '/', 'www.mydomain.com' );
//$_COOKIE['sfdc'] = 'cookie';
endif;
}
}
echo $_COOKIE['sfdc'];
}
if I access any page on the site with ?sfdc=mim, the value is shown. I assumed the cookie is set at that point, and when I check the stored cookies from the Chrome browser, it appears to be set. However, if the querystring is absent, it is as if the cookie does not exist. I cannot even echo the cookie onto the page.. Why can't I echo the value when the querystring is not present in the URL?
I have changed my add_action from send_headers to init with the same result.