Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By shinji_rem on
Hi,
is there a Drupal function to check if the user is logged or not?
Thanks for your support.
Comments
No function, but it is easy to do
No function, but it is easy to do, this code snippet should get you going
I am having a very strange
I am having a very strange thing happen.
In this scenario, the not logged in scenario outputs the string, but the logged in one doesn't. I am using a custom user block with this solution:
template.php contains this function:
function phptemplate_user_login($form) {
return _phptemplate_callback('user_login', array('form' => $form));
}
............................................................
Inside my user_login.tpl.php file:
I'm going to guess that user_login.tpl.php doesn't even get run when the user is logged in? Does anyone know how to arrange this otherwise?
Could it have to do with the "me" module?
I want the username/pass only in my login block (when not logged in)
When logged in, I want to see a logout link.
I figure this scenario 'should' work, but I have a hunch the custom template isn't even run when logged out.
Is there another "simple" way to do this? I've seen a few articles around but nothing doing just this.
I've searched all around DrupalLand. There are a tonne of resources for this simple task.
Could there be a config issue I'm missing?
How about two blocks?
How about two blocks? Use the standard login block for one and a custom block for the logout link with visibility set so it only shows for people logged in.
This wont work because
This wont work because anonymous user still has a uid
That's incorrect. Anonymous
That's incorrect. Anonymous users have a UID of 0 (zero). Zero in PHP evaluates to FALSE. Therefore the following code does work for checking if a user is logged in or not.
Hi nevets,
Hi nevets,
I am newbie to drupal, were this code is to be placed in order to check whether user is logged in if he/she wishes to view some content that would be visible for only those user who are logged in.
Thanks in advance.
will that work with drupal 6
will that work with drupal 6
Yep
Yes it will work in drupal 6.
--------------------------------------------------
http://zugec.com/drupal
---
WebWash: Drupal Tutorials and Videos
user_is_logged_in()
Starting in Drupal 6.x, there is a function to check whether the user is logged in: user_is_logged_in()
Hey Thank, it worked...
Hey Thank, it worked...
Aliya Khan, Front End Developer
Axelerant
user_is_logged_in()
For Drupal 6+ use this function user_is_logged_in()
Use the function
Use the user_is_logged_in() function like so:
User registered
PHP snippet
Proper way
https://api.drupal.org/api
https://api.drupal.org/api/drupal/modules!user!user.module/function/user... for Drupal 7
Also in a variable
Also, in pretty much every templates, $logged_in (boolean) is available.