-
Notifications
You must be signed in to change notification settings - Fork 1
/
XSS.php
38 lines (36 loc) · 906 Bytes
/
XSS.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
36
37
38
<!-- NoT fixed code -->
<!-- <html>
<body>
<form method="get">
<input type="text" name="name"><br>
<input type="submit">
<?php
// //Chack if the `name` premater is Existing or not to hide the errors
// if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
// //Welcome Message
// echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
// }
?>
</form>
</body>
</html> -->
<!-- fixed code -->
<html>
<body>
<form method="get">
<input type="text" name="name"><br>
<input type="submit">
<?php
// Chack if the name premater is Existing or not to hide the errors
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
//3 ways to protect the code ( just remove the comment `//`)
$name = htmlentities( $_GET[ 'name' ] );
$name = htmlspecialchars( $_GET[ 'name' ] );
$name = strip_tags( $_GET[ 'name' ] );
//Welcome Message
echo "<pre>Hello ${name}</pre>";
}
?>
</form>
</body>
</html>