Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to tell if a user is logged into Wordpress from looking at the cookies which are set on a site? If not, how could I add hooks to the login success and logout actions and set my own cookies?

share|improve this question
2  
It would help to actually know those reasons. People might not agree with them, but such things are relevant technically. –  Rarst Oct 9 '11 at 20:48
1  
Downvotes are a hint that there are issues with a question as community sees it. You have my downvote now, since you stressed your attitude instead of fixing it. –  Rarst Oct 10 '11 at 9:21
    
Wouldn't be a downvote (from my side), if you'd have taken the time to illustrate your needs instead saying: "I have my reasons and I don't care if you agree with them". This doesn't help any further readers, which is the purpose of this Q/A format. If you'd explain the why, later readers might get better insights whether your problem is related to their own or not. Btw: The attitude is more than just harsh and really not appreciated. –  kaiser Oct 10 '11 at 10:18
    
@Rarst - you're right. I've reworded the question. My apologies. –  cwd Dec 7 '11 at 18:20
    
@kaiser - you're right as well. I think I was frustrated by not being able to get Wordpress to work and should have spent more time on the question. I'm sorry and I've redone the question. –  cwd Dec 7 '11 at 18:22

1 Answer 1

up vote 1 down vote accepted

You could use Javascript

<script type="text/javascript">
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

var logged_in=getCookie("wordpress_logged_in_[HASH]");
  if (logged_in!=null && logged_in!="")
  {
  alert("You are logged in!");
  }
else
  {
   alert("You are logged out!");
  }
</script>

NOTE: Wordpress logged in cookie info can be found here. You'll need to figure out what your hash is and possibly use regex for the hash. (this is untested but should work)

JS cookie source

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.