Page 1 of 1

[SOLVED] Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 6:32 am
by AliGW
I have an icon menu that has a link to the login page for my members' only area. In the members' only area, there is going to be a matching menu to navigate the secure area. Where on the main site's menu I have the Log In option, I'd like to have Log Out in the members' area. Is it possible to add the logout script to a menu button?

https://www.eastipswichcameraclub.co.uk/

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 10:00 am
by Pablo
What you can do is link a dedicated logout page, where you add this script at the start of the page.

Code: Select all

<?php
session_start();
unset($_SESSION['username']);
unset($_SESSION['fullname']);
unset($_SESSION['role']);
?>

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 10:29 am
by AliGW
So an empty page with just that code? And do I set that to divert immediately to the index page?

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 10:58 am
by AliGW
This works well, however the LoginInfo object still shows me as logged in. Is there something else that we need to do to reset that?

Thanks.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 11:29 am
by Pablo
And do I set that to divert immediately to the index page?
You can use the 'redirect' option in the page properties or use code like this:

Code: Select all

<?php
session_start();
unset($_SESSION['username']);
unset($_SESSION['fullname']);
unset($_SESSION['role']);
header('Location: ./index.html');
exit;
?>
Once you are on a different page, the username value should no longer be valid.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 11:47 am
by AliGW
Yes - as I said, I have that working.

What about the issue with the LoginInfo object still showing me as logged in?

I log out of the members' area and am taken back to the index page - works nicely.
Then I go back to the login page.
Expected: my logininfo object will not show because I am now logged out.
Observed: the logininfo object still shows, even though I am a logged out user.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 12:39 pm
by Pablo
Once you are on a different page, the username value should no longer be valid.
It is still shows, then the session variables have not been reset.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 2:05 pm
by AliGW
I’ll try clearing cookies again and retest.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 2:23 pm
by AliGW
It is still happening, so session cookies are not being cleared. What can I do? It isn't actually logging me out at all.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 3:21 pm
by Pablo
Did you add the code at the very top of the page?

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 3:38 pm
by AliGW
I converted the object to a form. The code is at the very top of the page, yes. I haven't done anything to it. There is no other PHP code on the page.

Do you want a temporary login so you can see the issue?

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 3:58 pm
by AliGW
Just to say that the timeout logout (after ten minutes) logs the user out completely, so it's just the logout menu item that isn't working.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 4:42 pm
by Pablo
Do you mean that you have converted the logout button to a form?
That will not work with a link because the code expects to be called from a form.

The code I've shared is not the same.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 4:52 pm
by AliGW
No. I converted the login control to a form.

The logout is the menu item as you advised earlier in this thread - it links to a page containing the code you gave me earlier.

Am I supposed to put a logout button on the page linked to in the menu? If so, then that’s not really going to work for me.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 5:43 pm
by Pablo
The code from the logout button will not work in this case.
Instead, please use the code I have included in my initial reply.

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 6:17 pm
by AliGW
That’s what I am using. I don’t know why you think that I am using code from a logout button.

I have linked the menu item to a page that contains your code in its header. I’ve tried the code with and without exit; added at the end.

The page redirects to the index page. I set this in page properties.

The code is not logging me out as I remain logged in.

So, what now?

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 7:55 pm
by Pablo
You wrote:
I converted the object to a form. The code is at the very top of the page, yes. I haven't done anything to it.
So, that is why I thought you did not use my code.

Does the standard logout button work?

Re: Icon Menu: Log Out?

Posted: Fri Apr 24, 2026 8:43 pm
by AliGW
I’ll test some more tomorrow.

Thanks. 🙏

Re: Icon Menu: Log Out?

Posted: Sat Apr 25, 2026 5:00 am
by AliGW
A regular logout button works correctly.

And a clear head this morning has made me realise what was wrong. The code needed to be:

Code: Select all

<?php
session_start();
unset($_SESSION['username']);
unset($_SESSION['fullname']);
unset($_SESSION['role']);
header('Location: ./index.php');
exit;
?>
and the logout page needed a .php extension.

All is now working perfectly - thanks!!! :D