-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (72 loc) · 2.59 KB
/
index.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
<?php
$insert = false;
if(isset($_POST['name']))
{
$server = "localhost";
$username = "root";
$password = "";
$con = mysqli_connect($server, $username, $password);
if(!$con){
die("⚠ Connection to Database ❌Failed!❌ due to " .mysqli_connect_eror() );
}
// echo "Successful connection to Db ✅";
//POST Variables
$name = $_POST['name'];
$id = $_POST['id'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
//Encryption of important data
$key= 'vbecnkj4r78hvb3%#civ$nfir%09hfrj';
function encrypt($data, $key){
$encryption_key = base64_decode($key);
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
//the algorithm aes-256-cbc will ensure randomness even if the same data is encrypted many times with the same key
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
//ENCRYPT data to be stored in db
$nameencrypted = encrypt($name, $key);
$idencrypted = encrypt($id, $key);
$phoneencrypted = encrypt($phone, $key);
$emailencrypted = encrypt($email, $key);
$sql = "INSERT INTO `Transaction Form`.`Transaction FORM` (`name`, `id`, `phone`, `email`, `message`)
VALUES ('$nameencrypted', '$idencrypted', '$phoneencrypted', '$emailencrypted', '$message', current_timestamp());";
if($con->query($sql) == true){
$insert = true;
}
else{
echo "ERROR: $sql <br> $con->error";
}
$con->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Travel Information</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="formContainer">
<h2>Hi</h2>
<p> Enter your details for Confirmation!</p>
<?php
if($insert == true){
echo "<p class='.submitMesssage'>Your Response is Recorded ✅</p>";
}
?>
<form actions = "index.php" method="post">
<input type ="text" name ="name" palceholder ="Name">
<input type ="number" name="id" placeholder="Id">
<input type="number" name ="phone" placeholder="Phone Number">
<input type="text" name="email" placeholder="Email Id">
<textarea name="message" id="message" cols="15" rows="10" placeholder="Message"></textarea>
<button class="btn" >Submit</button>
<button class="btn" >Reset↺</button>
</form>
</div>
</body>
</html>