hello.. often I'd like to discriminate between anonymous and logged-in users.
I saw that with the right permissions I can use php on my content and I have the feeling that there must be an API function that return the "status" of the user, so I can use it to display separate messages.

Can anyone point me to the right place? Thank you ;-)

Comments

nevets’s picture

There is no API, code just uses the global $user, something like this

<?php
global $user;

if ( $user->uid ) {
  // They are logged in
}
else {
  // They are not loggin in
}
?>
sylvaticus’s picture

thanks, works greatly ;-)

Where can I get all the globals I can use ?

civicpixel’s picture

The easiest way I know of to get a list of all the globals is to print them out in your node or theme file using:

<pre><?php print_r($GLOBALS) ?></pre>

That will give you a formatted list of all the superglobals(all caps) and globals.

For a more detailed explanation see http://drupal.org/node/46200.

---
Brian Hiatt
Civic Pixel Ltd.

Open Media Foundation

cog.rusty’s picture

To save you some time, if you read past the superglobals and get to drupal's globals you won't find anything else of much interest. Most of the rest hold just a string and some are interesting only in a limited context. A grep in the core files shows:

$GLOBALS['user']

$GLOBALS['db_type']
$GLOBALS['active_db']
$GLOBALS['base_url']
$GLOBALS['base_path']
$GLOBALS['theme']
$GLOBALS['locale']

$GLOBALS['multibyte']
$GLOBALS['access_check']
$GLOBALS['pager_page_array']
$GLOBALS['pager_total']

$GLOBALS['form_values']
$GLOBALS['element']
$GLOBALS['item']
$GLOBALS['tag']

That is all. There are also some statics in some scopes.