-
Notifications
You must be signed in to change notification settings - Fork 0
/
020.php
82 lines (63 loc) · 1.7 KB
/
020.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
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>020 - Cookies | Session</title>
</head>
<body style="font-size: 1.1em">
<div style="background-color: gray;"><h2>Cookies</h2></div>
<?php
setcookie("phpbasico", "Esse é o meu cookie", time() + 10);
//setcookie("phpbasico", null, time() - 60); (removendo o cookie)
$cookie = filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
var_dump(
$_COOKIE,
$cookie
);
$time = time() + 60 * 60 * 24 * 7; // criar cookie no máximo 7 dias
$user = [
"user" => "root",
"passwd" => "12345",
"expire" => $time
];
setcookie(
"fratellilogin",
http_build_query($user),
$time,
"/",
"localhost",
true //somente acessado por https
);
$login = filter_input(INPUT_COOKIE, "fratellilogin", FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ($login){
var_dump($login);
var_dump($user);
}
?>
<div style="background-color: gray;"><h2>Session</h2></div>
<?php
session_name('PHPBASICOSESSID');
session_start();
$folder = __DIR__ . "/020-ses";
if (!file_exists($folder) || !is_dir($folder)) {
mkdir($folder, 0755);
}
var_dump($_SESSION,
[
"id" => session_id(),
"name" => session_name(),
"status" => session_status(),
"save_path" => session_save_path(),
"cookie" => session_get_cookie_params()
]
);
$_SESSION['login'] = (object)$user;
$_SESSION['user'] = (object)$user;
//unset($_SESSION['user']); tira uma sessão expecífica
//session_destroy();
?>
</body>
</html>