On your website, include this code at the top of each file:
<?php define('WP_USE_THEMES', false); require('./blog/wp-blog-header.php'); ?>
... if your blog is at ./blog/
.
It includes the entire wordpress stack. You will have access to all the wordpress features in your code. Thanks to this, you can easily check if the user is registered, roles and features, but also retrieve messages or so.
Then in your code to check the user:
if (is_user_logged_in()) { ... }
Code: is_user_logged_in ()
You can also specify a link to exit:
<a href="<?php bloginfo("url"); ?>/wp-login.php?action=logout/">Logout</a>
If your blog and your site are not in the same domain or subdomain, you need to configure the cookie domain in wp-config.php
define('COOKIE_DOMAIN', '.domain.com'); // Share cookie on all subdomains
EDIT
If you really want to read Wordpress cookies (which is a good choice for performance): the cookie name is stored in the AUTH_COOKIE constant.
AUTH_COOKIE is defined in /wp-includes/default-constants.php -> line 171
as
"wordpress_" + md5( get_site_option(siteurl) )
You should get or recount AUTH_COOKIE, then read $ _COOKIE [AUTH_COOKIE].
To analyze it, look at wp_parse_auth_cookie()
in wp-includes/pluggable.php @line 585
(indeed, the format is simple user|expiration|hmac
, so we divide the chain by |
and get the first element)