-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
120 lines (101 loc) · 3.23 KB
/
functions.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?
define("CONST_TIME", "24");
define("REFRESH_TIME", "8000");
class access {
/*sessions_company*//////////////////////////////////////////////
function sesion_destroy()
{
bd_ins('DELETE FROM `session` WHERE user='.$_SESSION['id']);
unset($_SESSION['id'],$_SESSION['first_name'],$_SESSION['last_name'],$_SESSION['email'],$_SESSION['key']);
setcookie(session_name(), session_id(), time()-60*60*CONST_TIME);
session_unset();
session_destroy();
}
function sesion_start($user)
{
session_start();
unset($_SESSION['id'],$_SESSION['first_name'],$_SESSION['last_name'],$_SESSION['email'],$_SESSION['key']);
$_SESSION['id'] = $user['id'];
$_SESSION['first_name'] = $user['first_name'];
$_SESSION['last_name'] = $user['last_name'];
$_SESSION['email'] = $user['email'];
$_SESSION['key'] = md5(uniqid(rand(), true));
$session = bd_ask('SELECT * FROM `session` where user = '.$user['id'],'');
if ($session['id'])
{
bd_ins('UPDATE `session` SET session_key="'.$_SESSION['key'].'", session_time='.time().' WHERE user='.$user['id']);
} else
{
bd_ins('INSERT INTO `session` (`session_key`, `session_time`, `user`) VALUES ( "'.$_SESSION['key'].'", '.time().', '.$_SESSION['id'].')');
}
}
/*Access*//////////////////////////////////////////////////////
function exit_panel($not_update)
{
$this->sesion_destroy();
if ($not_update==0) { header('Location: /');}
else if ($not_update==1) {echo ' window.location.href = "/";';}
}
function access_page($not_update)
{
if (isset($_REQUEST[session_name()]))
{
session_start();
$sesion = bd_ask('SELECT * FROM `session` where user = '.$_SESSION['id'],'');
$user = bd_ask('SELECT * FROM `user` where id = '.$_SESSION['id'],'');
if ((time()-$sesion['session_time'])<(60*CONST_TIME) && $sesion['session_key'] == $_SESSION['key'])
{
if ($not_update==0)
{
$_SESSION['key'] = md5(uniqid(rand(), true));
bd_ins('UPDATE `session` SET session_key="'.$_SESSION['key'].'", session_time='.time().' WHERE user='.$_SESSION['id']);
}
}
else
{
$this->exit_panel($not_update);
}
} else
{
$this->exit_panel($not_update);
}
}
}
/*Date time*//////////////////////////////////////////////
function split_date($input_date,$status)
{
$level1 = explode(" ", $input_date);
$date = explode(".", $level1[0]);
$time = explode(":", $level1[1]);
$ret['d']=$date[2];
$ret['mon']=$date[1];
$ret['y']=$date[0];
$ret['h']=$time[0];
$ret['min']=$time[1];
if ($status==1)
{
return $ret['d'].'.'.$ret['mon'].'.'.$ret['y'].' '.$ret['h'].':'.$ret['min'];
} else
{
return $ret;
}
}
/*Data base*//////////////////////////////////////////////
function bd_ins($input_request)
{
mysql_query($input_request);
return mysql_insert_id();
}
function bd_ask($input_request, $input_field)
{
$request = mysql_query($input_request);
$request_ans = mysql_fetch_array($request);
if ($input_field == '')
{
return $request_ans;
} else
{
return $request_ans[$input_field];
}
}
?>