How to hide a link from non-authenticated users
eatanicecream - April 9, 2008 - 11:43
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?
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?
Anonymous users have an id
Anonymous users have an id of 0.
<?php
global $user;
if ($user->uid != 0) {
// display link
}
?>
Hope that helps!
__________________________________________________________
Mark Theunissen
Code Baboon
Drupal based services
Thanks! I don't really know
Thanks! I don't really know what to do with it though, I don't know PHP at all...
Oh I see, sorry I wasn't
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
Well, I didn't really like
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.
Ok then try put this code in
Ok then try put this code in the page.tpl.php where you want the link to appear:
<?php
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
Thanks! It works.
Thanks!
It works.
Oh I see, sorry I wasn't
[deleted duplicate post]