Log out link
Posted: Mon Aug 18, 2008 11:52 pm
Hello everyone!
I'm fairly new to PHP and am working on creating a custom CMS. Right now, I have a table called "admin_users" with records of my admin users (first_name, last_name, username, password). When a user submits the login form, if the query that runs finds a username/password match in the db, I use the following code:
to start a session, set a valid to yes (which is checked on every page and if not "yes" they get redirected to the login form), and set the user name they posted to a session variable.
Now I'm trying to create a "log out" link. Here's what I did on the first try:
That sets a link to my logout page, which checks:
I supposed that if $_SESSION[valid] must remain "yes" in order for the user to remain logged in, setting it to "" (nothing) would kick the user out and make him/her log in again. However, it does nothing. The user stays logged in and can still perform tasks.
What is the proper way to handle a log out using a link? Any help with this would be greatly appreciated. I'm open to any and all criticism.
I'm fairly new to PHP and am working on creating a custom CMS. Right now, I have a table called "admin_users" with records of my admin users (first_name, last_name, username, password). When a user submits the login form, if the query that runs finds a username/password match in the db, I use the following code:
Code: Select all
session_start();
$_SESSION['valid'] = "yes";
$_SESSION['user'] = $_POST['username'];
header("Location: ../index.php");
Now I'm trying to create a "log out" link. Here's what I did on the first try:
Code: Select all
<a href="index.php?c=logout&task=1" title="Logout">Log Out</a>Code: Select all
if ($_GET[task] == 1 ) {
$_SESSION[valid] = "";
header('Location: skin/login.php');
exit;
}What is the proper way to handle a log out using a link? Any help with this would be greatly appreciated. I'm open to any and all criticism.