-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateTransfer.php
128 lines (106 loc) · 4.33 KB
/
createTransfer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html>
<head>
<title>E-Corp - Transfer response</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand" href="/">E-Corp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="bankTransfers.php">Payment History</a>
</li>
</ul>
</div>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
Welcome <b>Elliot</b>
</li>
</ul>
</div>
</nav>
</div>
<div class="container mt-5 text-center">
<?php
//Take parameters from post
$recipient = $_POST['recipient'];
$amount = $_POST['amount'];
$causal = $_POST['causal'];
$server = "database";
$username = "user";
$password = "password";
$db_name = "db";
// Create connection
$conn = new mysqli($server, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// create table if not exist
$sql = "CREATE TABLE IF NOT EXISTS bank_transfers(
id int AUTO_INCREMENT PRIMARY KEY,
sender varchar(20),
receiver varchar(20),
amount int,
causal text);";
if ($conn->query($sql) === TRUE) {
// echo "Table bank_transfers created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
//sanitaze parameters to prevent xss
// $recipient = htmlspecialchars($recipient);
// $amount = htmlspecialchars($amount);
// $causal = htmlspecialchars($causal);
//This parameter in the real world has to be get from database
$from = get_sender_from_coockie();
// insert data into db
$sql = "INSERT INTO bank_transfers(sender, receiver, amount, causal) VALUES(
'$from',
'$recipient',
$amount,
'$causal');";
// echo $sql;
if ($conn->query($sql) === FALSE) {
echo "Error executing query: " . $conn->error;
}else{
$curl = curl_init();
$request_url = "http://backend:8081?recipient=$recipient&from=$from&amount=$amount&causal=$causal";
//for testing purpouses
// echo $request_url;
curl_setopt_array($curl, array(
CURLOPT_URL => $request_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
<p class="display-6"><?php echo ($response); ?></p>
<?php } ?>
<a href="/">Go back home</a>
</div>
</body>
<?php
function get_sender_from_coockie()
{
return "Elliot";
}
?>
</html>