-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.php
41 lines (36 loc) · 1.2 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
<?php
$cookie_name = "username";
$cookie_value = "John Doe";
$expireTime = time() + 20; // 86400 = 1 day
setcookie($cookie_name, $cookie_value, $expireTime , "/");
session_start();
$sission_1 = 'first';
$sission_2 = 'second';
$_SESSION[$sission_1] = 'First Session!';
$_SESSION[$sission_2] = 'Second Session!';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style/index.css">
<title>Session and Cookies</title>
</head>
<body>
<h1>Session and Cookies</h1>
<h2>Cookie</h2>
<?php
// Cookie
if(isset($_COOKIE[$cookie_name])) echo "
<strong>$_COOKIE[$cookie_name]</strong> is the value of $cookie_name cookie which will expire after ".($expireTime-time())." seconds";
else echo "cookie $cookie_name is not set";
echo "<br><h2>Session</h2>";
// Session
print_r($_SESSION);
echo "<br>session varible 1 is $_SESSION[$sission_1]<br>";
echo " session varible 2 is $_SESSION[$sission_2]<br>";
?>
</body>
</html>