//initialize the session
if (!isset($_SESSION)) {
session_start();
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
if (isset($_COOKIE['MM_Uname'])&&isset($_COOKIE['MM_CookiePass'])){
$loginUsername=$_COOKIE['MM_Uname'];
$password=md5($_COOKIE['MM_CookiePass']);
$MM_fldUserAuthorization = "Paswoord";
mysql_select_db($database_conn, $conn);
$LoginRS__query=sprintf("SELECT chirosite_users.Login , chirosite_users.cookiePasswd , chirosite_groepen.Naam
FROM chirosite_users, chirosite_groepen, chirosite_groepUser WHERE ((chirosite_users.Login = '%s')AND (chirosite_users.cookiePasswd = '%s')AND(chirosite_groepUser.groep = chirosite_groepen.id)AND (chirosite_groepUser.user = chirosite_users.id))",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'chirosite_groepen.Naam');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
setcookie('MM_Uname',$_COOKIE['MM_Uname'],time()+604800);
setcookie('MM_CookiePass',$_COOKIE['MM_CookiePass'],time()+604800);
}
else{
//delete the cookie used to remember the login
setcookie('MM_Uname', '',time()-3600);
setcookie('MM_CookiePass', '',time()-3600);
//When remember is set, an random password "cookiePasswd" is generated. The password will first be stored in the usertable as an md5 encrypted password. After this the unencrypted password and the md5 encrypted login are stored in a cookie.
$updateSQL = sprintf("UPDATE chirosite_users SET cookiePasswd=NULL WHERE login=%s",
GetSQLValueString($_POST['login'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
}
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
mysql_select_db($database_conn, $conn);
//delete the cookie used to remember the login
setcookie('MM_Uname', '',time()-3600);
setcookie('MM_CookiePass', '',time()-3600);
//When remember is set, an random password "cookiePasswd" is generated. The password will first be stored in the usertable as an md5 encrypted password. After this the unencrypted password and the md5 encrypted login are stored in a cookie.
$updateSQL = sprintf("UPDATE chirosite_users SET cookiePasswd=NULL WHERE login=%s",
GetSQLValueString($_SESSION['MM_Username'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
}
?>