Skip to content

Commit e8ed5f1

Browse files
committed
Added cookies code
1 parent f8b81bc commit e8ed5f1

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

public/chapter7/delete_cookie.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
// set the expiration date to one hour ago
3+
setcookie("username", "", time() - 3600);
4+
?>
5+
<html>
6+
<body>
7+
8+
<?php
9+
echo "Cookie 'user' is deleted.";
10+
?>
11+
12+
</body>
13+
</html>

public/chapter7/first_cookie.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
$cookie_name = "username";
3+
$cookie_value = "Betchy McCleaver";
4+
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
5+
?>
6+
<html>
7+
<body>
8+
9+
<?php
10+
if(!isset($_COOKIE[$cookie_name])) {
11+
echo "Cookie named '" . $cookie_name . "' is not set!";
12+
} else {
13+
echo "Cookie '" . $cookie_name . "' is set!<br>";
14+
echo "Value is: " . $_COOKIE[$cookie_name];
15+
}
16+
?>

public/chapter7/modify_cookie.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
$cookie_name = "username";
3+
$cookie_value = "Jason Bourne";
4+
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
5+
?>
6+
<html>
7+
<body>
8+
9+
<?php
10+
if(!isset($_COOKIE[$cookie_name])) {
11+
echo "Cookie named '" . $cookie_name . "' is not set!";
12+
} else {
13+
echo "Cookie '" . $cookie_name . "' is set!<br>";
14+
echo "Value is: " . $_COOKIE[$cookie_name];
15+
}
16+
?>
17+
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)