Posted by firecentaur on November 28, 2012 at 11:45am
Hi there, I need to check if a user is logged in, before executing some code when my javascript gets triggered on a button press
however, I have not been able to determine how to do this in javascript.
I have searched stack-overflow, and the web, and have found nothing that seams to work. I hope you can help!
I am using Drupal 6.16,
I have tried using this method:
var cookie_value = jQuery.cookie("DRUPAL_UID");
if(cookie_value != 0)
{
// execute some code...
}
but I always get "null"
I have thought of setting a variable in my PHP and passing it to javascript, but what happens when the user logs out?
Comments
Can you show us how you are
Can you show us how you are you adding your javascript to the page?
Jaypan We build websites
A javascript setting should
A javascript setting should be OK, using something like
<?phpdrupal_add_js(array('mymodule'=>array('loggedin' => $loggedin)), 'setting');
?>
If you are using page caching then every cached page will be one built for an anonymous user, so they'll all have the correct value.