WordPress – working with cookies – PHP

The WordPress server side script is PHP.
As such you can set, read & delete cookies each time the page is reloaded.

You can use AJAX responses to work with cookies without reloading page, however javascript might be a better approach.

Setting Cookies
setcookie( $name, $value, 30 * DAYS_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );

Reading cookies
if(!isset($_COOKIE[$name])) {
        echo “The cookie: ‘” . $name. “‘ is not set.”;
} else {
        echo “The cookie ‘” . $name. “‘ is set.”;
        echo “Cookie is: ” . $_COOKIE[$name];
}

Deleting and/or cookies
unset( $_COOKIE[$v_username] );
setcookie( $v_username, ”, time() – ( 15 * 60 ) );}

Adwords (1)

Branding (13)

CMS (3)

CSS (6)

Graphic Design (6)

Javascript (1)

PHP (3)

SEO (5)

tech support (5)

Web Design (10)

Web Development (10)

Wordpress (17)

Wordpress plugins (3)