HostRefugee-Vince
05-10-2007, 06:34 PM
Hi Everyone,
I have created a simple script to handle logging in and out of an admin area. Everything was good, until I start to show it off to a design client. While trying to logout of the software, the script wouldn't log out. Perhaps it's a cookie issue unique to Vista?
Anyhow, both the login and logout parts of the code are included below. If anyone notices something that may affect Vista users, I would highly appreciate it if you could point it out.
This is not the full code, so if it is missing a curly... That's not the problem!
<?php
include ("config.php");
# Include the config.php file
if (empty($online['id'])){
# If they're not logged in already
if ($_POST['Login']) {
# If the login was made
$user = clean($_POST['username']);
# clean the username
$pass = clean($_POST['password']);
# clean the password
if (!$user | !$pass) {
# if either of the fields are empty
$errormessage = "You left a field blank.";
include ("./templates/tpl_login.php");
die();
} else {
$pass = md5($pass);
/*
Make the password a hash so hopefully it'll
be equal to atleast one of the passwords in
the database
*/
$sql = "SELECT * FROM `admin` WHERE username = '$user' AND password = '$pass'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$rights = $row['rights'];
# Select the row of the user logging in
if (mysql_num_rows($result) == 1){
# If a row with the right information is found...
$expire = time() + 60*15;
# Well set an expire time for the cookie, in this case a week.
setcookie("username", $user, $expire);
# Set a cookie for the username
setcookie("password", $pass, $expire);
setcookie("rights", $rights, $expire);
$pagename = "FPA Manager - Main Menu";
include ("./templates/tpl_header.php");
include ("./templates/tpl_redirect.php");
} else {
# If no rows were found with the given information
$errormessage = "Incorrect username or password. " . $pass;
include ("./templates/tpl_login.php");
}
}
} else {
# The form wasn't submitted
include ("./templates/tpl_login.php");
die();
}
} else {
//IF P IS NOT DEFINED SHOW HOMEPAGE
if ($_GET['p'] == '') {
$pagename = "FPA Manager - Main Menu";
include ("./templates/tpl_header.php");
if($_COOKIE['rights'] == 'super') {
include ("./templates/tpl_index.php");
} else {
include ("./templates/tpl_index_2.php");
}
}
//IF P EQUALS LOGOUT, THEN LOG THEM OUT
elseif ($_GET['p'] == 'logout') {
setcookie("username", "", 0);
setcookie("password", "", 0);
setcookie("rights", "", 0);
$online['id'] = '';
echo '<meta http-equiv="Refresh" Content="0; URL=index.php">';
echo '<div align="center" style="font14Bold">You have been logged out, you are being redirected...</div>';
die();
}
I have created a simple script to handle logging in and out of an admin area. Everything was good, until I start to show it off to a design client. While trying to logout of the software, the script wouldn't log out. Perhaps it's a cookie issue unique to Vista?
Anyhow, both the login and logout parts of the code are included below. If anyone notices something that may affect Vista users, I would highly appreciate it if you could point it out.
This is not the full code, so if it is missing a curly... That's not the problem!
<?php
include ("config.php");
# Include the config.php file
if (empty($online['id'])){
# If they're not logged in already
if ($_POST['Login']) {
# If the login was made
$user = clean($_POST['username']);
# clean the username
$pass = clean($_POST['password']);
# clean the password
if (!$user | !$pass) {
# if either of the fields are empty
$errormessage = "You left a field blank.";
include ("./templates/tpl_login.php");
die();
} else {
$pass = md5($pass);
/*
Make the password a hash so hopefully it'll
be equal to atleast one of the passwords in
the database
*/
$sql = "SELECT * FROM `admin` WHERE username = '$user' AND password = '$pass'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$rights = $row['rights'];
# Select the row of the user logging in
if (mysql_num_rows($result) == 1){
# If a row with the right information is found...
$expire = time() + 60*15;
# Well set an expire time for the cookie, in this case a week.
setcookie("username", $user, $expire);
# Set a cookie for the username
setcookie("password", $pass, $expire);
setcookie("rights", $rights, $expire);
$pagename = "FPA Manager - Main Menu";
include ("./templates/tpl_header.php");
include ("./templates/tpl_redirect.php");
} else {
# If no rows were found with the given information
$errormessage = "Incorrect username or password. " . $pass;
include ("./templates/tpl_login.php");
}
}
} else {
# The form wasn't submitted
include ("./templates/tpl_login.php");
die();
}
} else {
//IF P IS NOT DEFINED SHOW HOMEPAGE
if ($_GET['p'] == '') {
$pagename = "FPA Manager - Main Menu";
include ("./templates/tpl_header.php");
if($_COOKIE['rights'] == 'super') {
include ("./templates/tpl_index.php");
} else {
include ("./templates/tpl_index_2.php");
}
}
//IF P EQUALS LOGOUT, THEN LOG THEM OUT
elseif ($_GET['p'] == 'logout') {
setcookie("username", "", 0);
setcookie("password", "", 0);
setcookie("rights", "", 0);
$online['id'] = '';
echo '<meta http-equiv="Refresh" Content="0; URL=index.php">';
echo '<div align="center" style="font14Bold">You have been logged out, you are being redirected...</div>';
die();
}
