Для Пупкина писано

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
ob_start();
session_start();
try {
$db_host = 'localhost';
$db_name = 'test';
$db_user = 'root';
$db_pass = '';
$option = array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
$db = new pdo("mysql:host=".$db_host.";dbname=".$db_name, $db_user, $db_pass, $option);
} catch(PDOException $e) {
print $e->getMessage();
}
$id = isset($_GET['id']) ? abs(intval($_GET['id'])) : null;
require_once 'functions.php';
if(isset($_COOKIE['login']) && isset($_COOKIE['pass'])){
$login = $_COOKIE['login'];
$pass = $_COOKIE['pass'];
if(empty($login) || empty($pass)){
setcookie('login', '', $login, time() + 3600 * 24 * 365, '/');
setcookie('pass', '', $login, time() + 3600 * 24 * 365, '/');
}
$user = $db->prepare("SELECT * FROM users WHERE login = ? AND pass = ?");
$user->execute(array($login, $pass));
$rows = $user->fetch(PDO::FETCH_ASSOC);
$user = $rows['id'];
if(isset($rows['id'])){
if($rows['login'] !== $login || $rows['pass'] !== $pass){
setcookie('login', '', $login, time() + 3600 * 24 * 365, '/');
setcookie('pass', '', $login, time() + 3600 * 24 * 365, '/');
}
}
}
?>