Что то типа так. Дальше сам

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if(isset($_COOKIE['login']) && isset($_COOKIE['pass'])){
$login = check($_COOKIE['login']);
$password = check($_COOKIE['pass']);
$pass = md5(md5($password));
if(empty($login) || empty($pass)){
setcookie('login', '', time()-cookie_time, '/');
setcookie('pass', '', time()-cookie_time, '/');
}
$user = $db->prepare("SELECT * FROM users WHERE login = ? AND pass = ?");
$user->execute(array($login, $pass));
$rows = $user->fetch(PDO::FETCH_ASSOC);
if(isset($rows['id'])){
if($rows['login'] !== $login || $rows['pass'] !== $pass){
setcookie('login', '', time()-cookie_time, '/');
setcookie('pass', '', time()-cookie_time, '/');
}
}
}