php Запускаем сессии session_start Подключение базе данных db_host iss

 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
# Запускаем сессии
session_start();
# Подключение к базе данных
$db_host = isset($db_host) ? $db_host : 'localhost';
$db_user = isset($db_user) ? $db_user : '';
$db_pass = isset($db_pass) ? $db_pass : '';
$db_name = isset($db_name) ? $db_name : '';
$connect = @mysql_connect($db_host, $db_user, $db_pass) or die('Cannot connect to database server');
@mysql_select_db($db_name) or die('Specified database does not exist');
@mysql_query("SET NAMES 'utf8'", $connect);
# Подключение через сессию
if (isset($_SESSION['id_user']) && mysql_num_rows(mysql_query("SELECT `id` FROM `user` WHERE `id` = '$_SESSION[id_user]' LIMIT 1"))==1)
{
$user = intval($_SESSION['id_user']);
# Запрос в базу о посещении
mysql_query("UPDATE `users` SET `click` = ". time() ." WHERE `id` = '". $user['id'] ."' LIMIT 1");
}
else
# Подключение через COOKIE
if (isset($_COOKIE['id_user']) && isset($_COOKIE['pass']) && $_COOKIE['id_user']!=NULL && $_COOKIE['pass']!=NULL)
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `id` = ". intval($_COOKIE['id_user']) ." AND `pass` = '". md5($_COOKIE['pass'], intval($_COOKIE['id_user']))."' LIMIT 1"), 0)==1)
{
$user = intval($_COOKIE['id_user']);
$_SESSION['id_user'] = $user['id'];
# Запрос в базу о посещении
mysql_query("UPDATE `users` SET `click` = ". time() ." WHERE `id` = '". $user['id'] ."' LIMIT 1");
}
else
{
setcookie('id_user');
setcookie('pass');
}
}
# Загрузка функций
include_once ($_SERVER['DOCUMENT_ROOT']."/heart/include/function.php");
?>