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 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
    }
});

```
If you have access to your .HTACCESS File add this code.

It checks if Wordpress default logged in cookie is present & if so it sets cookie "hello".

If it detects "wordpress\_logged\_in" cookie is not present it removes/expires "hello" cookie.

```
<If "%{HTTP_COOKIE} =~ /wordpress_logged_in/">
        Header add Set-Cookie "hello;secure;path=/"
</If>

<If "%{HTTP_COOKIE} !~ /wordpress_logged_in/">
       Header add Set-Cookie "hello;secure;Expires=Wed, 21 Oct 1963 07:28:00 GMT"
</If>

```

HttpOnly is not set on "hello" cookie therefore you can access it by javascript.