-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_action.php
58 lines (45 loc) · 1.39 KB
/
demo_action.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSRF-Protection Demo Using Synchronizer Token Pattern</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<script>
$(function() {
$.ajax({
type: 'POST',
url: 'ajax_call.php',
success: function(result) {
console.log(result);
const res = JSON.parse(result);
console.log(res.token);
alert(res.token);
document.getElementById('csrfToken').value = res.token;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("some error");
}
});
});
</script>
<body>
<?php include 'common.php';?>
<div class="container">
<div class="row">
<h4>Welcome Admin!</h4>
<form action="result.php" method="POST">
<input type="hidden" name="csrfToken" id="csrfToken" value="token">
<div class="form-group">
<label for="resource_name">Resource Name</label>
<input type="text" name="resource_name" value="Resource one">
</div>
<button type="submit" class="btn btn-danger">Delete Resource</button>
</form>
</div>
</div>
</body>
</html>