Creating urls htaccess automatic limiting minimum amount of characters

0
RewriteRule ^(.*)/([0-9]+)$ /nomes.php?nome=$1&matricula=$2

I need to determine that the $ name redirection is at least three characters long.

I did something like this:

    $nome = @$_POST['nome'].@$_GET['nome'];

    if( strlen( $nome ) < 3){
    echo "Erro!";
    exit();
}

Solved my problem. How do I modify this to also add that: If the $ name is not in the database it also returns error?

The check would be with the:

$arrayReturn['nome']
    
asked by anonymous 11.07.2018 / 00:28

1 answer

1

Check out the answer from

var_dump ($nome)
var_dump ($arrayReturn['nome'])

And the logic is the same

if( $nome <> $arrayReturn['nome']){
        echo "Erro!";
        exit();
    }

If I understand correctly, the return of $ arrayReturn ['name'] should be something like: Stack Overflow and $ name stack-overflow

Am I right? Then add the function:

<?php
/***
 * Função para remover acentos de uma string
 *
 * @autor Thiago Belem <[email protected]>
 */
function removeAcentos($string, $slug = false) {
  $string = strtolower($string);
  // Código ASCII das vogais
  $ascii['a'] = range(224, 230);
  $ascii['e'] = range(232, 235);
  $ascii['i'] = range(236, 239);
  $ascii['o'] = array_merge(range(242, 246), array(240, 248));
  $ascii['u'] = range(249, 252);
  // Código ASCII dos outros caracteres
  $ascii['b'] = array(223);
  $ascii['c'] = array(231);
  $ascii['d'] = array(208);
  $ascii['n'] = array(241);
  $ascii['y'] = array(253, 255);
  foreach ($ascii as $key=>$item) {
    $acentos = '';
    foreach ($item AS $codigo) $acentos .= chr($codigo);
    $troca[$key] = '/['.$acentos.']/i';
  }
  $string = preg_replace(array_values($troca), array_keys($troca), $string);
  // Slug?
  if ($slug) {
    // Troca tudo que não for letra ou número por um caractere ($slug)
    $string = preg_replace('/[^a-z0-9]/i', $slug, $string);
    // Tira os caracteres ($slug) repetidos
    $string = preg_replace('/' . $slug . '{2,}/i', $slug, $string);
    $string = trim($string, $slug);
  }
  return $string;
}

And change to:

if( $nome <> str_replace(" ","-",removerosAcentos($arrayReturn['nome'])) ){
        echo "Erro!";
        exit();
    }
    
11.07.2018 / 16:00