0
votes

I want to display this text link, <p><a href ="register">Click here to register.</a></p> in the body of a larger block of text on a page and but I want the link to show up when some is logged in. I want to use php conditional to show this other link when someone is instead anonymous on the site,

<p>You need to login before you can register. Please <a href="login">Click here to login.</a>

I want a code like:

<?php
if user=="logged-in";
    echo "<a href ='register'>Click here to register.</a>";
    else echo "<a href ='login'>Click here to login.</a>"
?>

I know I must not have written perfect php but I do not have problems with the php, what I need is the Drupal syntax for if user == "logged-in" and if user == "not-logged-in".

I do not want to use a block and start setting visibility by role. I want to use code as described.

Thanks.

1

1 Answers

0
votes

See the docs

You want something like this. Both of your link descriptions need some work though. What you'd most likely want to do is display both the register and the login link to anonymous users.

<?php
 if (user_is_logged_in()){
   //user is logged in
 }
 else{
   //user is not logged in
 }
?>