Skip to content

Commit feb9501

Browse files
committed
Added code 🚀
1 parent dfbfedc commit feb9501

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Intermediate/6_cookies.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Cookies</title>
8+
<link rel="shortcut icon" href="../favicon.png" type="image/x-icon">
9+
</head>
10+
11+
<body>
12+
<h1 style="text-align: center;">Cookies</h1>
13+
<?php
14+
// Set cookie
15+
$cookie_name = "user";
16+
$cookie_value = "John Doe";
17+
echo time() . "<br>";
18+
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
19+
echo "Cookie '" . $cookie_name . "' is set!<br>";
20+
21+
if (isset($_COOKIE['users'])) {
22+
echo "Value is: " . $_COOKIE['users'] . "<br>";
23+
} else {
24+
echo "Cookie 'users' is not set! <br>";
25+
}
26+
?>
27+
</body>
28+
29+
</html>

Intermediate/7_cookiesForm.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Cookie Form</title>
8+
<link rel="shortcut icon" href="../favicon.png" type="image/x-icon">
9+
<style>
10+
.error {
11+
color: red;
12+
}
13+
h1{
14+
text-align: center;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<h1>Cookies</h1>
21+
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="text-align: center; margin-top: 20px;">
22+
<label for="user" style="font-size: 1.2em; margin-right: 10px;">User:</label>
23+
<input type="text" name="user" id="user" style="padding: 5px; font-size: 1em;">
24+
<input type="submit" name="set" value="Set" style="padding: 5px 10px; font-size: 1em; margin-left: 10px;">
25+
<input type="submit" name="del" value="Delete" style="padding: 5px 10px; font-size: 1em; margin-left: 10px;">
26+
</form>
27+
<?php
28+
if(isset($_POST['set'])){
29+
$cookie = $_POST['user'];
30+
setcookie($cookie, $cookie, time() + (86400 * 30), "/");
31+
echo "Cookie '" . $cookie . "' is set!<br>";
32+
}
33+
34+
if(isset($_POST['del'])){
35+
$cookie1 = $_POST['user'];
36+
setcookie($cookie1, "", time() - 3600, "/");
37+
echo "Cookie '" . $cookie1 . "' is deleted!<br>";
38+
}
39+
?>
40+
</body>
41+
42+
</html>

0 commit comments

Comments
 (0)