Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom dia pessoal, estou com um problema.
Sou iniciante em php e criei um site para cadastro de curriculos, porem estou com medo que o site sofra algum ataque. Dei uma lida de como bloquear o site contra sql injection e nao entendi muita coisa.
Vou postar um dos meus codigos e se alguem poder me mostrar como ficaria meu codigo protegido eu agradeceria.
Muito Obrigado.
<html>
<head>
<title>Cadastro de Curriculum</title>
<script language='JavaScript'>
function SomenteNumero(e){
var tecla=(window.event)?event.keyCode:e.which;
if((tecla > 47 && tecla < 58 || tecla == 9)) return true;
else{
if (tecla != 8) return false;
else return true;
}
</script>
<style type="text/css">
<!--
.titulo {
font-size: 18px;
color: #FFF;
}
.Sub-titulo {
color: #FFF;
font-weight: bold;
font-size: 16px;
}
.Ds-Dados {
font-size: 12px;
}
-->
</style>
</head>
<body>
<?php
function ConverteData($Data){
if (strstr($Data, "/"))//verifica se tem a barra /
{
$d = explode ("/", $Data);//tira a barra
$rstData = "$d[2]-$d[1]-$d[0]";//separa as datas $d[2] = ano $d[1] = mes etc...
return $rstData;
} elseif(strstr($Data, "-")){
$d = explode ("-", $Data);
$rstData = "$d[2]/$d[1]/$d[0]";
return $rstData;
}else{
return "Data invalida";
}
}
if ($submit) {
if (!$cpf || !$pass || !$email || !$email2 || !$confirma_senha) {
$error = "Favor preencher todos os campos!";
} else {
if($pass == $confirma_senha && $email == $email2)
{
include"conecta.php";
$resultado = mssql_query("select * from Candidato where CodCandidato = '$cpf'");
//$conferir = mssql_result($resultado, 0, 'CodCandidato');
$qt_registro = 0;
$qt_registro = mssql_num_rows ($resultado);
$dia = date(d);
$mes = date(m);
$ano = date(y);
$h_data = $dia .'/' .$mes .'/20' .$ano;
$criacao = ConverteData($h_data);
//VERIFICA SE O FORMULÁRIO FOI ENVIADO
if($_POST["verOK"]) {
//RECEBE OS DADOS DO FORMULÁRIO
$cpf = $_POST["cpf"];
//VERIFICA SE O QUE FOI INFORMADO É NÚMERO
if(!is_numeric($cpf)) {
$status = false;
}
else {
//VERIFICA
if( ($cpf == '11111111111') || ($cpf == '22222222222') ||
($cpf == '33333333333') || ($cpf == '44444444444') ||
($cpf == '55555555555') || ($cpf == '66666666666') ||
($cpf == '77777777777') || ($cpf == '88888888888') ||
($cpf == '99999999999') || ($cpf == '00000000000') ) {
$status = false;
}
else {
//PEGA O DIGITO VERIFIACADOR
$dv_informado = substr($cpf, 9,2);
for($i=0; $i<=8; $i++) {
$digito[$i] = substr($cpf, $i,1);
}
//CALCULA O VALOR DO 10º DIGITO DE VERIFICAÇÂO
$posicao = 10;
$soma = 0;
for($i=0; $i<=8; $i++) {
$soma = $soma + $digito[$i] * $posicao;
$posicao = $posicao - 1;
}
$digito[9] = $soma % 11;
if($digito[9] < 2) {
$digito[9] = 0;
}
else {
$digito[9] = 11 - $digito[9];
}
//CALCULA O VALOR DO 11º DIGITO DE VERIFICAÇÃO
$posicao = 11;
$soma = 0;
for ($i=0; $i<=9; $i++) {
$soma = $soma + $digito[$i] * $posicao;
$posicao = $posicao - 1;
}
$digito[10] = $soma % 11;
if ($digito[10] < 2) {
$digito[10] = 0;
}
else {
$digito[10] = 11 - $digito[10];
}
//VERIFICA SE O DV CALCULADO É IGUAL AO INFORMADO
$dv = $digito[9] * 10 + $digito[10];
if ($dv != $dv_informado) {
$status = false;
}
else
$status = true;
}//FECHA ELSE}//FECHA IF($_POST)
if($qt_registro >= 1)
{
$error = "CPF já consta em nosso banco de dados";
}
else
{
if($_POST["verOK"]) {
if($status) $cpass = base64_encode($pass);
mssql_query("INSERT INTO Candidato (CodCandidato, Email, Pass) VALUES ($cpf, '$email', '$cpass')");
mssql_query("INSERT INTO ComplementoCandidato (CodCandidato, NroCpf) VALUES ($cpf, '$cpf')");
mssql_query("INSERT INTO CandidatoWeb (CodCandidato, Ultima_atualizacao) VALUES ($cpf, '$criacao')");
//mssql_query("INSERT INTO idiomascandidato (CodCandidato) VALUES ($cpf)");
}
else $error = "CPF é INVÁLIDO";
?>
<script language="JavaScript">
alert('CPF INVALIDO');
location.href="cadastro_login.php";
</script>
<?php
}
}
?>
<script language="JavaScript">
alert('Cadastro OK');
//location.href="index.php?cpf=<?php echo($cpf) ?>& email=<?php echo($email) ?>";
location.href="index.php";
</script>
<?php
}
mssql_close($con);
}}
}
if (!$submit || $error) {
echo $error;
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<p> </p>
<center>
<table width="970" border="3">
<tr>
<td align="center" bgcolor="#0000CC"><strong class="titulo"><em>Cadastramento de Candidato</em></strong></td>
</tr>
</table>
</center>
<p> </p>
CPF:
<input type="text" name="cpf" id="cpf" maxlength="11" onkeypress='return SomenteNumero(event)' value="<?php echo $cpf ?>"><br>
Senha:
<input type="password" name="pass" id="pass" size="56" maxlength="10" value="<?php echo $pass ?>"><br>
Confirma Senha:
<input type="password" name="confirma_senha" id="confirma_senha" size="56" maxlength="10" maxlength="20" value="<?php echo $confirma_senha ?>"><br>
Email:
<input type="text" name="email" id="email" size="56" maxlength="40" value="<?php echo $email ?>"><br>
Confirma Email:
<input type="text" name="email2" id="email2" size="56" maxlength="40" value="<?php echo $email2 ?>">
<input type="Submit" name="submit" value="Next">
<input type="hidden" name="verOK" value="1">
<?php
} // end if
?>
</body>
<p>
</html>
Muito Obrigado!
Carregando comentários...