I want to add a link to the site header 'Create account or login', like you see on most wiki sites. The page.tpl.php template doesn't seem to have any info on the user.

Is there anybody who can tell me how to do this?

Comments

profix898’s picture

page.tpl.php doesn't seem to have any info on the user.

I dont understand what you means with that!? What do you want to do
exactly? For a link to create account or login you can simply point to
'user/register' or 'user' appended to your $base_url.
<?php global $base_url; echo $base_url.'/user/register'; ?>
or even simpler <a href="./user/register">Login</a>
All information about a user (when logged on) is available through
the global variable $user.

stephencarr’s picture

You would only want this to appear if you were not logged in. How does one test to see if you are an authenticated user or not?

Anonymous’s picture

if ($user->uid > 0) {
  // show the login url
}
else {
  // show welcome text
}

-----------------------------------------
CompuBase, websites and webdesign

garg_art’s picture

This idea looks cool....
Is there a way to make Login/logout appear in the primary link or any other menu item conditionally toggling?
Thanks for your help.

pelicani’s picture

To add the Login/MyAccount link to your primary nav (or any drupal menu)
add a new link to /user and label it as you want (i.e. Login)
When a user is logged in, it will be transformed into 'My Account'.

To add a logout link
add a link to your menu that points to /logout
label it as you want (i.e. Logout)
This link will only display if you are actually logged in.

peace,
michael

Web Developer : RockRiverStar.com : Philadelphia, PA

Technical Architect : Philadelphia, PA

mattyoung’s picture

I've been trying to find this answer, can you show me some code snippet and where this code should go? Does this go into a module's hook_menu() function?

pelicani’s picture

I was trying to do this on a dv6 install and it doesn't work. boo-urns.
The solution does still work on my install of dv5.7

Technical Architect : Philadelphia, PA

pelicani’s picture

there is a module that does this for you.
http://drupal.org/project/loginmenu

Technical Architect : Philadelphia, PA

prateek_t2’s picture

/user does not hide the link after login, instead use /user/login

canishk’s picture

@ prateek_t2 Thanks,

It works.

2ndmile’s picture

Since a uid greater than 0 would mean that the user is in fact logged in the code should read:


if ($user->uid > 0) {
// show welcome text
}
else {
// show the login url
}

Anonymous’s picture

right

mattyoung’s picture

ekushay’s picture

Hi guys :D

I'm really new to all this and I don't have much experience with HTML or whatnot in general [just in the process of learning~], so I have a really newbie question XD I'm wondering where you would put in all those codes that have been posted above (^) ...

I've got the Account Menu module but I'm not sure how to work with it to make the Login an actual link in the header >____<

Thank you all in advance! ^^

Mamoun’s picture

You can just add a "user/login" link into the menu instead of just "user" to have it as a login link when the user is not logged in and it would then disappear when he/she is logged in.

tinker’s picture

You can also create a link to 'user/register' which will display a link to the registration page only if the user is anonymous (not logged in) just like the 'login' link mentioned above.

anne-pierre’s picture

And it was as simple as that! thank you! I was wondering how to get rid of the "login" link when user is logged in! Where is my brain?

markbannister’s picture

User menu
add item with path user/login

hitendrasinh’s picture

Hi markbannister ,Thank you so much buddy.It works for all pages, earlier solutions by other people was working for only home page in my case.thanks :-)

squarecandy’s picture

if ($user->uid > 0) {
	print l(t('my account'), 'user') . ' &nbsp;|&nbsp; ' . l(t('logout'), 'logout');
}
else {
	print l(t('login'), 'user');
}