Creating automatic htaccess urls limiting minimum number of characters

Asked

Viewed 49 times

0

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

I need to determine that the $name redirect has at least three characters.

I did something like this:

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

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

Solved my problem. As 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']
  • 2

    The variable $nome is of the correct value? Of a var_dump and checks

  • Actually, the answer was NULL. I added: $name = @$_POST['name']. @$_GET['name']; and it worked.

  • 1

    @Guilhermecostamilam, I made a modification to the question.

1 answer

1


Check out the response of

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 the $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();
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.