-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample1.php
More file actions
39 lines (32 loc) · 910 Bytes
/
example1.php
File metadata and controls
39 lines (32 loc) · 910 Bytes
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
<?php
// Start the session
session_start();
if (!empty($_POST)) {
//set the values to what was in the form
if (isset($_POST["color"])) {
$_SESSION["favcolor"] = $_POST["color"];
}
if (isset($_POST["animal"])) {
$_SESSION["favanimal"] = $_POST["animal"];
}
}
else{
//user didn't fill the form, using default
$_SESSION["favcolor"] = "blue";
$_SESSION["favanimal"] = "giraffe";
}
?>
<!DOCTYPE html>
<html>
<body>
<h2>Demo sessions 1: </h2>
<form method="post">
<label for="color">Favorite color:</label>
<input type="text" name="color" /><br />
<label for="animal">Favorite animal:</label>
<input type="text" name="animal" /><br /><br/>
<input type="submit" value="Submit" name="submit" /><br/><br/>
<input type="submit" value="What was recorded?" formaction="color_animal_session.php"/>
</form>
</body>
</html>