-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolução SQL Injection [Issue #857]
- Loading branch information
1 parent
d474123
commit 782080f
Showing
1 changed file
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
<?php | ||
|
||
session_start(); | ||
if (!isset($_SESSION["usuario"])){ | ||
if (!isset($_SESSION["usuario"])) { | ||
header("Location: ../../index.php"); | ||
} | ||
|
||
// Verifica Permissão do Usuário | ||
require_once '../permissao/permissao.php'; | ||
permissao($_SESSION['id_pessoa'], 11, 7); | ||
|
||
$id_dependente = trim(filter_input(INPUT_POST, 'id_dependente', FILTER_SANITIZE_NUMBER_INT)); | ||
|
||
require_once "../../dao/Conexao.php"; | ||
$pdo = Conexao::connect(); | ||
$id_dependente = $_POST["id_dependente"]; | ||
if (!$id_dependente || $id_dependente < 1) { | ||
http_response_code(400); | ||
echo json_encode(['erro' => 'O id de um dependente deve ser um inteiro positivo maior ou igual a 1.']); | ||
exit(); | ||
} | ||
|
||
try { | ||
require_once "../../dao/Conexao.php"; | ||
$pdo = Conexao::connect(); | ||
|
||
$dependente = $pdo->query("SELECT *, par.descricao AS parentesco | ||
FROM funcionario_dependentes fdep | ||
LEFT JOIN pessoa p ON p.id_pessoa = fdep.id_pessoa | ||
LEFT JOIN funcionario_dependente_parentesco par ON par.id_parentesco = fdep.id_parentesco | ||
WHERE fdep.id_dependente = $id_dependente;"); | ||
$dependente = $dependente->fetchAll(PDO::FETCH_ASSOC)[0]; | ||
$dependente = json_encode($dependente); | ||
$stmt = $pdo->prepare('SELECT *, par.descricao AS parentesco | ||
FROM funcionario_dependentes fdep | ||
LEFT JOIN pessoa p ON p.id_pessoa = fdep.id_pessoa | ||
LEFT JOIN funcionario_dependente_parentesco par ON par.id_parentesco = fdep.id_parentesco | ||
WHERE fdep.id_dependente = :idDependente'); | ||
|
||
echo $dependente; | ||
$stmt->bindParam(':idDependente', $id_dependente); | ||
$stmt->execute(); | ||
|
||
die(); | ||
$dependente = $stmt->fetch(PDO::FETCH_ASSOC); | ||
|
||
echo json_encode($dependente); | ||
} catch (PDOException $e) { | ||
http_response_code(500); | ||
echo json_encode(['erro' => 'Erro no servidor ao listar dependente.']); | ||
exit(); | ||
} |