/* Если пользователь существует в БД, то проверяем его активацию */
try {
include $_SERVER['DOCUMENT_ROOT'].'/chat/dsn.php';
$activation ='';
$login = $_POST['login'];
$password = md5($_POST['password'] . 'swl');
$sql = 'SELECT activation FROM users WHERE login = :login AND password = :password';
$s = $dsn->prepare($sql);
$s->bindValue(':login', $login);
$s->bindValue(':password', $password);
$s->execute();
}
catch (PDOException $e) {
echo $e->getMessage();
exit();
}
$activation = $s->fetch(PDO::FETCH_COLUMN);
if ($activation !=1) {
include $_SERVER['DOCUMENT_ROOT'].'/chat/admin/erroractivation.html';
exit();
}
/* Если активирован задаем значения сессии */
if(session_id() == '') {session_start();}
$_SESSION['loggedIn'] = TRUE;
$_SESSION['login'] = $_POST['login'];
$_SESSION['password'] = $password;
return TRUE;
}
else
{
if(session_id() == '') {session_start();}
unset($_SESSION['loggedIn']);
unset($_SESSION['login']);
unset($_SESSION['password']);
$GLOBALS['loginError'] =
'Указанный логин или password не совпадают.';
return FALSE;
}
}
if (isset($_POST['action']) and $_POST['action'] == 'logout')
{
if(session_id() == '') {session_start();}
unset($_SESSION['loggedIn']);
unset($_SESSION['login']);
unset($_SESSION['password']);
unset($_SESSION['userid']);
header('Location: ' . $_POST['goto']);
exit();
}
if(session_id() == '') {session_start();}