repl.it
@ThomasS1/

Cookies!

PHP Web Server

Yum

fork
loading
Files
  • index.php
index.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
<?php
if (array_key_exists('name', $_GET) and array_key_exists('value', $_GET)) {
	if (array_key_exists('exp', $_GET)) {
		setcookie($_GET['name'], $_GET['value'], time() + $_GET['exp']);
	}
	else {
		setcookie($_GET['name'], $_GET['value']);
	}
	header("Location: /"); # reloads once cookie has been added so it is visible
}
?>
<html>
	<h1>Mmm, cookies!</h1>
	<h3>Current cookies for this website:</h3>
	<ul>
		<?php
foreach ($_COOKIE as $key => $value) {
	echo "<li>{$key}: {$value}</li>";
}
		?>
	</ul>
	<p>The <code>__cfduid</code> cookie is a standard cookie that exists on certain systems, if it is in the list above you can ignore it.</p>
	<h1>Give me cookies!</h1>
	<h3>Set more cookies for this website:</h3>
	<form>
		<input type="text" placeholder="Name" name="name" pattern="^[^=,; \t\r\n\013\014]+$"></input>
		<input type="text" placeholder="Value" name="value" pattern="^[^=,; \t\r\n\013\014]+$"></input>
		<input type="number" placeholder="Expiry time (s from now)" name="exp" min="0"></input>
		<button type="submit">Set cookie!</button>
	</form>
	<p><code>Name</code> and <code>Value</code> cannot contain any of <code>=,;</code> or whitespace</p>
	<p>Expiry time must be a positive integer. If it is blank, the cookie will expire at the end of the user's browser sesison.</p>
	<p>In case it wasn't obvious, <b>the use of this website requires that you accept our use of cookies!!</b> We will not place any cookies on your computer other than those you set, and cannot read the cookies you set. We do not accept any responsibility for data read/deleted by third parties from the cookies - this is not a safe way to store sensitive data!</p>
	</body>
</html>
?