problem with Logout

henry4 - May 17, 2007 - 11:55

Guys i'm facing a problem.The problem is that i created a logout facillity in my primary link which is at extreme right below the logo of my site.Now when i click logout it's working but the problem is that as soon as i click logout twice it's showing a page with a message like this
Access denied

You are not authorized to access this page. Instead i want to show the user home page even if he clicks that twice.How do i do that?please i need a help or else i will commit suicide.HELPME!!!!!!!!!! FAST

Check the URL

bchoc - May 17, 2007 - 19:02

No need for the drama.

In summary, to ensure I understand -- if you are already logged out, and you click your logout button, you get "Access denied"?

I'm going to guess that if you go to the Site building > Menus > Primary links and open your logout menu item, you've got a Path in there that looks something like "http://www.example.com/logout". If you change that menu Path to be just "logout", Drupal should hide the logout button when the user is not logged in. This will prevent people who are not logged in from trying to log out (and getting the error).

thanks but

henry4 - May 18, 2007 - 04:31

thanks for that help but this is not the primary link i'm talking about.i have designed a primary link on my own and i have disabled the primary links that comes along with drupal.What i did was i did some modification in page.tpl.php
now what i want is that is there any php code so that if a user clicks the logout link twice he shouldn't be shown the access denied page instead he should be shown the home page
Thank you

Hello

Ole Martin - May 18, 2007 - 23:54

Hello
I had done the same, made my own "primary link" and made a button for "log In" and "Log Out". I hade the same problem, until I tried wath
bchoc write. And it works fin. Now the "Log in" button dissaper after log in and visaversa with the "Log Out" button.
Site: http://www.examtoday.com

Ole Martin
http://www.drupal1.no
http://foreldrekontakten.com/

hi

henry4 - May 21, 2007 - 05:37

Buddy can you please share that code with me please

I found my way to here from

daggett - May 22, 2007 - 14:38

I found my way to here from another forum topic.

I am still not sure how to have a simple 'login' menu item (linked to "?q=user") appear on the navigation menu when the user is anonymous and a 'logout' menu item appear only when the user is logged in.

Without any coding or extra modules ...

bchoc - May 22, 2007 - 17:09

... I have used three ways to give logins to anonymous users and logout to signed-in users. I've used each of these at various times, depending on what I want to accomplish.

First, Drupal out-of-the-box does not allow menu-item access control, but it does allow block control. Create two blocks, one for anonyous and one for authenticated users, and into these blocks put menus that are identical except for certain items that only logged in/out users should see. You can disable the Navigation menu completely, if you want, to gain greater control, and then have two "Main Menu" blocks, nearly identical. It's annoying to maintain two menus, but I have found this gives a great deal of flexibility, and the page users don't know that the two menus are different ... they only see the changed items.

Second, you can use the "user login" block, which will disappear when someone is logged in. Personally, I'm not a big fan since it feels rather, well, blunt to me, but it will work.

Third, add to any menu an item with the path "user" and another with the path "logout" right next to each other. No domain info or anything like that -- just the one word as the path. The "logout" item, whatever you have called it, will only appear on the menu when someone is logged in. The "user" item will appear as a login when the user is not logged in, and as "my account" when the user is logged in. I use the user<->my account menu change as a feature (especially in the "primary links" menu), but if you don't want it there at all it'd be annoying.

simple fix.

spatz4000 - May 22, 2007 - 14:45

This is the logic you need to apply to your menu code, so that it hides the logout link for non-logged in users. It's functional code but not complete.

if ($user->uid) {
echo "logout"; //display your menu with the logout link in this block of code.
} else {
echo " . . ."; //display your menu here withOUT the link in this block of code.
}

Thanks

henry4 - May 23, 2007 - 03:37

Thanks a lot guys i will try all those.thanks a lot

Thanks for all the help

daggett - May 23, 2007 - 09:28

I found that simply addding menu items for 'Log in' linked to the path 'user' and 'Log out' linked to the path 'logout' seems to do the trick well enough on drupal version 5.1 after all.

So coding and setting up more blocks seesm unnecessary for the time being, but thanks for the useful insights all the same.

 
 

Drupal is a registered trademark of Dries Buytaert.