Question: there is a way to check wordpress cookie **wordpress\_logged\_in** using jquery?

I'm using cloudflare full caching, so there is no way to check if user is logged or not than this cookie, I tried to read it using jquery but seems protected and not visible, I can access it only using PHP.

Here is how I can read it right now :

```
$logged_in = 'no'; 
if (count($_COOKIE)) {
    foreach ($_COOKIE as $key => $val) {
        if (preg_match("/wordpress_logged_in/i", $key)) {
            $logged_in = 'yes';
        }       
    }
}

```

Maybe there is a possiblity to check it simply by jquery, but I didn't find how.

Thanks for helping

Answer: 
You can't access to wordpress cookies named `wordpress_logged_in` using `js/jquery` just because it's flagged as [`HttpOnly`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies):

> 
> A secure cookie is only sent to the server with a encrypted request
>  over the HTTPS protocol... To prevent cross-site scripting (XSS)
>  attacks, HttpOnly cookies are inaccessible to JavaScript's
>  Document.cookie API; they are only sent to the server.
> 
> 
> 

But since 3.0 wordpress add one more cookie named [wp-settings-{time}-[UID]](https://codex.wordpress.org/WordPress_Cookies#WordPress_.3E_3.0) when user log in:

> 
> WordPress also sets a few wp-settings-{time}-[UID] cookies. The number
>  on the end is your individual user ID from the users database table.
>  This is used to customize your view of admin interface, and possibly
>  also the main site interface.
> 
> 
> 

And you can get this cookie using `js/jquery`. So, you can even get user ID from cookies.

Here is working js function for getting cookies and checking, if user is logged in:

```
function getLoggedInCookie() {
    var cookie = document.cookie.indexOf('wp-settings-time') !== -1;

    if(cookie){
        alert('Logged in');
    }else{
        alert('Not User');
    }
}
getLoggedInCookie();

```

jQuery solution will be to include [Cookie plugin](http://plugins.jquery.com/cookie/) to your wordpress theme/plugin and try to use it( may need in some modifications ).

**NOTE:**

Provided code will work with login forms, which use standart WordPress functions and endpoints, such as `http://{website-name}/wp-admin/` or `http://{website-name}/wp-login.php`. Third party plugins could not set cookies named `wp-settings-{time}-[UID]`.
You can create ajax request to check if user logged in:

in functions.php:

```
function ajax_check_user_logged_in() {
    echo is_user_logged_in()?'yes':'no';
    die();
}
add_action('wp_ajax_is_user_logged_in', 'ajax_check_user_logged_in');
add_action('wp_ajax_nopriv_is_user_logged_in', 'ajax_check_user_logged_in');

function load_my_scripts()
{
    wp_localize_script('my-ajax-handle', 'the_ajax_script', array('ajaxurl' => admin_url('admin-ajax.php')));
}

add_action('wp_enqueue_scripts', 'load_my_scripts');

```

in js: 

```
var data = {
    action: 'is_user_logged_in'
};

jQuery.post(the_ajax_script.ajaxurl, data, function(response) {
    if(response == 'yes') {
        // user is logged in
    } else {
        // user is not logged in
    }
});

```