Função AntiInjection para PHP
function antiInjection($str)
#
{
#
# Remove palavras suspeitas de injection.
#
$str = preg_replace(sql_regcase("/(\n|\r|%0a|%0d|Content-Type:|bcc:|to:|cc:|Autoreply:|from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"), "", $str);
#
$str = trim($str); # Remove espaços vazios.
#
$str = strip_tags($str); # Remove tags HTML e PHP.
#
$str = addslashes($str); # Adiciona barras invertidas à uma string.
#
return $str;
#
}
Função para Validar o CNPJ
cnpj,
funçao,
php,
valida
|
0
comentários
function testaCNPJ( $cnpj )
{
$cnpj = preg_replace( "@[./-]@", "", $cnpj );
if( strlen( $cnpj ) <> 14 or !is_numeric( $cnpj ) )
{
return false;
}
$k = 6;
$soma1 = "";
$soma2 = "";
for( $i = 0; $i 13; $i++ )
{
$k = $k == 1 ? 9 : $k;
$soma2 += ( $cnpj{$i} * $k );
$k--;
if($i < 12)
{
if($k == 1)
{
$k = 9;
$soma1 += ( $cnpj{$i} * $k );
$k = 1;
}else{
$soma1 += ( $cnpj{$i} * $k );
}
}
}
$digito1 = $soma1 % 11 < 2 ? 0 : 11 - $soma1 % 11;
$digito2 = $soma2 % 11 < 2 ? 0 : 11 - $soma2 % 11;
return ( $cnpj{12} == $digito1 and $cnpj{13} == $digito2 );
}
Função para Validar o CPF
cpf,
funçao,
php,
valida
|
0
comentários
function testaCpf($cpf)
{
$cpf = str_pad(ereg_replace('[^0-9]', '', $cpf), 11, '0', STR_PAD_LEFT);
if (strlen($cpf) != 11 || $cpf == '00000000000' || $cpf == '99999999999') {
return false;
} else {
for ($i = 9; $i 11; $i++) {
for ($tot = 0, $j = 0; $j < $i; $j++) {
$tot += $cpf{$j} * (($i + 1) - $c);
}
$tot = ((10 * $tot) % 11) % 10;
if ($cpf{$j} != $tot) {
return false;
}
}
return true;
}
}
Assinar:
Postagens (Atom)
