-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprevent_sql_injection_basic
More file actions
51 lines (36 loc) · 943 Bytes
/
Copy pathprevent_sql_injection_basic
File metadata and controls
51 lines (36 loc) · 943 Bytes
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
<?php
//conexao SQLI
$sqli = mysqli_connect("localhost","_your_database_username_","_your_password_here","_your_database_here");
//Consulta
//SELECT campos{id,nome,senha} FROM tabela{usuario} WHERE nome=indefinido{?}
$sql = "SELECT id,nome,senha FROM usuario WHERE nome=?";
//Preparo da consulta
$st = $sqli->prepare($sql);
if(!$st){
die("Erro ao preparar");
}
//Variaveis(el), provenientes do formulario
$usr = "teste1";
//$usr = "teste' OR 1=1; --'";
$usr = preg_replace("/\W/","",$usr);
$usr = mysqli_real_escape_string($sqli,$usr);
//Saida da variavel definida
echo $usr."<br/>";
$bnd = $st->bind_param("s",$usr);
if(!$bnd){
die("Erro ao vincular");
}
$exec = $st->execute();
if(!$exec){
die("Erro ao executar");
}
$st->bind_result($id,$nome,$senha);
while($st->fetch()){
echo "ID: ". $id. "<br/>";
echo "NOME: ". $nome. "<br/>";
echo "SENHA: ". $senha. "<br/>";
}
$st->free_result();
$st->close();
$sqli->close();
?>