-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconexao 27-11-23.php
More file actions
71 lines (66 loc) · 1.87 KB
/
conexao 27-11-23.php
File metadata and controls
71 lines (66 loc) · 1.87 KB
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
<?php
ob_start();
var_dump($_REQUEST);
function open_database() {
try {
$conn = new mysqli('localhost', 'id21420608_qihome', '012458913Jaaj!', 'id21420608_bd');
$conn -> set_charset ("utf8");
return $conn;
echo ("\nConexão criada.\n");
} catch (Exception $e) {
echo "<h3>Conexão mal-sucedida:\n<br>" . $e->getMessage() . "</h3>";
return null;
}
}
function close_database($conn) {
try {
mysqli_close($conn);
echo ("\nConexão encerrada.\n");
} catch (Exception $e) {
echo "<h3>Erro ao fechar conexão:\n<br>" . $e->getMessage() . "</h3>";
}
}
$senha_ext = "a4XXFt";
$senha_exe = "";
$sensor = "";
$estado = "";
$continue = true;
//while ($continue == true)
//{
sleep(3);
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
echo("\nCondição de requisição POST.\n");
$senha_exe = $_POST["senha_exe"];
if($senha_exe == $senha_ext)
{
echo("\nSenha bem verificada.\n");
// set parameters
$sensor = $_POST["sensor"];
$estado = $_POST["estado"];
$database = open_database();
$sql = "INSERT INTO tbl_status_sensor(sensor, estado) VALUES ('$sensor', '$estado');";
try {
$database->query($sql);
$_SESSION['message'] = 'Registro cadastrado com sucesso.';
$_SESSION['type'] = 'success';
echo($_SESSION['message']);
} catch (Exception $e) {
$_SESSION['message'] = "\n<h3>Não foi possivel realizar a operação:\n<br>" . $e->getMessage() . "<h3>\n";
$_SESSION['type'] = 'danger';
echo($_SESSION['message']);
}
sleep(3);
close_database($database);
}
else {
echo "ERRO DE SEGURANÇA.";
}
}
else {
echo "No data posted with HTTP POST.";
}
ob_flush();
ob_end_clean();
sleep(1);
//}