-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckCookie.php
More file actions
84 lines (55 loc) · 2.76 KB
/
checkCookie.php
File metadata and controls
84 lines (55 loc) · 2.76 KB
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
<?php
function checkCookie($page){
try
{
$bdd = new PDO('mysql:host=localhost;dbname=yoda;charset=utf8', 'root', 'cetroxNEST');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
if (isset($_COOKIE['yoda'])){
$cookie = $_COOKIE['yoda'];
$parts = explode('====', $cookie);
$id_user = $parts[0];
$delete = 'fuck';
$select = $bdd->query('SELECT USR_DELETE FROM YDA_USERS WHERE USR_ID ="'.$id_user.'"');
while ($query = $select->fetch()){
$delete = $query['USR_DELETE'];
}
// if($delete === null){
$select = $bdd->query('SELECT * FROM YDA_SESSION WHERE SES_ID_USR ="'.$id_user.'"');
$sessionCookie = [];
while ($query = $select->fetch()){
$sessionCookie['token'] = $query['SES_TOKEN'];
$sessionCookie['timeout'] = new Datetime($query['SES_TIMEOUT']);
}
$expected = $id_user . '====' . $sessionCookie['token'] . '====' . $sessionCookie['timeout']->format('Y-m-d H:i:s');
$now = new DateTime(date('Y-m-d H:i:s'));
$interval = $now->diff($sessionCookie['timeout']);
if ($expected == $cookie && intval($interval->format('%R%a')) > 0 ){
$_SESSION['login'] = 'ok';
$_SESSION['id_user'] = $id_user;
$_SESSION['token'] = $sessionCookie['token'];
$now->modify('+4 days');
$_SESSION['timeout'] = $now->format('Y-m-d H:i:s');
$req = $bdd->prepare('UPDATE YDA_SESSION SET SES_TIMEOUT = :timeout WHERE SES_ID_USR = :id_user');
$req->execute(array(
'id_user' => $id_user,
'timeout' => $now->format('Y-m-d H:i:s')
)) or die(print_r($bdd->errorCode()));
}
}
if(!isset($_SESSION['login']) || $_SESSION['login'] != 'ok'){
header('Location: login.php?redirect='.$page);
}else if(!isset($_SESSION['id_user']) || $_SESSION['id_user'] == ''){
header('Location: login.php?redirect='.$page);
}else{
setcookie('yoda', $_SESSION['id_user'] . '====' . $_SESSION['token'] . '====' . $_SESSION['timeout'], time() + 60 * 60 * 24 * 4);
// echo "<p style='color:white;'>Création cookie OK, veuillez fournir cette variable à Yohann : ". 'plop' ."</p>";
}
// }else{
// // header('Location: logout.php');
// echo 'plop du cul';
// }
}