Skip to content

Commit a4189f9

Browse files
authored
Update 13_sessions.php
learning sessions-1.0
1 parent 0d7bbc6 commit a4189f9

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

13_sessions.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?
1+
<?php
22

33
/*
44
Eng: Sessions are a way to store information ( in variables ) to be used across multiple pages . Unlike cookies , sessions are stored on the server.
@@ -8,22 +8,18 @@
88

99
//Sessions:
1010

11-
if (isset($_POST['submit'])) {
12-
//Eng: 1a option: || Pt: 1a opcao
13-
// $name = htmlspecialchars($_POST['name']);
14-
// $age = htmlspecialchars($_POST['age']);
15-
16-
//Eng: 2a option: || Pt: 2a opcao
17-
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
18-
$age = filter_input(INPUT_POST, 'age', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
19-
echo $name;
20-
echo $age;
21-
}
11+
12+
if(isset($_POST['submit'])){$username= filter_input(INPUT_POST,'username', FILTER_SANITIZE_SPECIAL_CHARS ) ; $password = $_POST['password'];
13+
14+
if ($username == 'john' && $password = 'password') {
15+
$_SESSION ['username'] = $username; header('Location : /php-crash/extras/dashboard.php');
16+
} else{echo }
17+
2218
?>
2319

2420
<!--HTML-->
2521
<!--Form-->
26-
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
22+
< form action = " < ? php echo htmlspecialchars ( $ _ SERVER [ ' PHP_SELF ' ] ) ; ? > " method = " POST " >
2723
<div>
2824
<label for="name">Name: </label><input type="text" name="name" required></input>
2925
</div>

0 commit comments

Comments
 (0)