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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
St_Aug_Beach_BumAuthor Commented:
Yes, it does - thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.