Reputation: 54776
Wordpress sets several cookies with a random hash appended. How can I use Javascript (and regex?) to find out if a cookie named wordpress_logged_in_XXXXXXXXXXXXXXXXXX
exists and what the name of it is?
Picture.png http://img9.imageshack.us/img9/3453/pictureje.png
Upvotes: 3
Views: 646
Reputation: 348992
document.cookie
is a string which contains all cookies, excluding the HTTP-only cookies.
To get any cookie which matches wordpress_logged_in_....
, use:
document.cookie.match(/wordpress_logged_in_[a-z0-9]{32}=([^;]+)/)[1];
Explanation of pattern:
wordpress_logged_in_ # literally
[a-z0-9]{32} # This fragment appears to be a md5 hash
= # literal =, separates a cookie key from its value
([^;]+) # Create a group, containing all consecutive non-; chars
# ; marks the end of a cookie key-value pair.
Upvotes: 4