javascript check to see if wordpress login cookie exists

I need a way, with javascript, to check to see if a user is logged in to my wordpress site.

I'm thinking maybe there's a way to check to see if a wordpress log in cookie exists?

Something along the lines of

if log in cookie exists
  //do this

Can you show me an example of how to do this?

(can't use php, as this will be on a cached page).

Thanks for any help you can provide,

Chris
St_Aug_Beach_BumAsked:
Who is Participating?
 
Avinash ZalaWeb ExpertCommented:
You can use function at below URL to check cookie existence:
http://stackoverflow.com/a/5968306

Now to generate Cookie name, you can use Cookie hash constant provided by WordPress:

1) wordpress_<?php echo COOKIEHASH;?>
2) wordpress_logged_in_<?php echo COOKIEHASH;?>

Hope this helps.
0
 
Avinash ZalaWeb ExpertCommented:
As per WordPress Codex:

WordPress > 3.0

On login, wordpress uses the wordpress_[hash] cookie to store your authentication details. Its use is limited to the admin console area, /wp-admin/

After login, wordpress sets the wordpress_logged_in_[hash] cookie, which indicates when you're logged in, and who you are, for most interface use.

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.

So you can look for those cookies using JavaScript and you have everything you needed.
0
 
St_Aug_Beach_BumAuthor Commented:
Hi Avinash,

Can you provide an example of how to do this?

Thanks,

Chris
0
 
St_Aug_Beach_BumAuthor Commented:
Yes, it does - thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.