-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.php
77 lines (66 loc) · 1.84 KB
/
session.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
<?php
/**
* This page is for session actions
*/
$lifetime = 60 * 10; //in seconds
session_start();
setcookie(session_name(),session_id(),time()+$lifetime);
/**
* This function ends session
* @return void
*/
function end_session(){
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
//session_start();
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();
header("Location: test_list.php");
}
if(isset($_POST['unlogin'])){
end_session();
}
//You already have login
if(isset($_SESSION['gds']['login']))
return;
//loggining
do if(isset($_POST['login']) || isset($_POST['password'])){
if($_POST['login'] == "" || $_POST['password'] == ""){
break;
}
$login = addslashes($_POST['login']);
$sql = "SELECT * FROM Users WHERE Login='$login'";
$result = $mysqli->query($sql) OR my_die("Ошибка: ".$mysqli->error);
$row = $result->fetch_array();
$psw = $row['Pass'];
if($psw == $_POST['password']){
$_SESSION['gds']['login'] = $login;
header("Location: {$_SERVER['REQUEST_URI']}");
} else {
$login = "";
}
}
while(false);
//login and password mismatch
if(isset($login) && $login == ""){
require_once('header.php');
include('login_page.html');
my_die("Неверный логин или пароль", "warning");
}
//no login given
if(!isset($login)){
require_once('header.php');
include('login_page.html');
my_die("Нужно войти в систему", "info", "");
}