Hi I am working on an web application using PHP and Oracle.
I have a logout link on each page. What I need to know is if the User at any point clicks on the logout link the user should not be able to go back to any of the earlier pages and should be given a message that they are logged out.
How can I do this in PHP.
I am using header () in my files (and so cannot use sessions ) and also am using the ADOdb Abstraction layer.
Please help !!
Thanks in advance.
HELP with Logout issues in PHP
Moderator: General Moderators
Hi,
I use header() in my scripts, and they do include sessions. I use output buffering and if I use header() to, say, redirect, I just ob_end_clean() and then redirect.
I track my user-based session variable to see if it exists. If it does, then the user is logged in and may enter restricted pages, otherwise it was destroyed when they logged out and they cannot.
Hope that helps.
I use header() in my scripts, and they do include sessions. I use output buffering and if I use header() to, say, redirect, I just ob_end_clean() and then redirect.
I track my user-based session variable to see if it exists. If it does, then the user is logged in and may enter restricted pages, otherwise it was destroyed when they logged out and they cannot.
Hope that helps.
Try something like this (off the top of my head, haven't tested it!):
Assuming that you're testing to see if they are logged in, using a session variable called "user":
On the logout page, use:
to destroy the session.
Hope that this helps.
Assuming that you're testing to see if they are logged in, using a session variable called "user":
Code: Select all
ob_start();
session_start();
echo "HELLO WORLD!"; // or in reality, any other code that causes headers to be sent
if(!isset($_SESSION["user"])){
ob_end_clean();
header("location: ./mypath/errorPage?errorText=" . urlencode("- You are not logged in"));
}
echo "<br/>";
echo "Hello " . $_SESSION["user"];
ob_end_flush(); //This will send the whole htmlCode: Select all
unset($_SESSION["user"]);Hope that this helps.