Hi

I would like to put a link at the bottom to my web statistics, but I only want to show it to logged-in users.

How would I do that?

Comments

Mark Theunissen’s picture

Anonymous users have an id of 0.


global $user;

if ($user->uid != 0) {
 // display link
}

Hope that helps!

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

eatanicecream’s picture

Thanks! I don't really know what to do with it though, I don't know PHP at all...

Mark Theunissen’s picture

Oh I see, sorry I wasn't sure so I gave a solution for use in code.

How are you displaying your web statistics? Is this link going to be in a block?

If your link is in a block, then you can simple configure the block to only display for authenticated users.

Does that help?

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

eatanicecream’s picture

Well, I didn't really like the standard statistics module so I installed the GetClicky webstats module. All it does is put in the necessary Javascript on each page, then you have to go to the GetClicky website to see the stats.

To make it easier for my client I want to have a link to the GetClicky page, but I only want it to appear when the client is logged in.

It's not a block, I just put the links directly into the page.tpl.php file.

You can see it at www.lcd-enar.org - the link will be added to the links in the footer.

Mark Theunissen’s picture

Ok then try put this code in the page.tpl.php where you want the link to appear:

global $user;

if ($user->uid != 0) {
  print '<a href="http://xxxx">click here for stats</a>';
}

it basically says "get the global user (i.e. the current user viewing the page), and if their user id is not 0 (i.e. they are not anonymous), then print out the link.

Let me know if it doesn't wors... it should work though, can't test right now but will be able to later if there are problems.

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

eatanicecream’s picture

Thanks!

It works.

Mark Theunissen’s picture

[deleted duplicate post]