in_array with friendly URL

0

I'm applying friendly URl with explode, doing the following:

$url = isset( $_GET['url'] ) ? addslashes( $_GET['url'] ) : '';
$url = rtrim( $url, '/');
$explode = explode('/',$url);

Everything works perfectly, I'm already doing it dynamically, making the products look like this:

http://localhost/produtos/camara-de-ar
  

STRUCTURE:

The idea is that when you do not find the url, in this case, the product (eg, camera-of-air-test), display the error page, and this works perfectly. However, the previously reported error is displayed before the file is added.

} elseif($explode[0] == 'produtos'){ // se for igual a produtos
    if(isset($explode[1]) && in_array($categorias[$explode[1]], $categorias) || !isset($explode[1]) || $explode[1] == ''){
        include ("pages/".$explode[0].".php");
    } else {
        include("pages/erro.php");
    }
}
  

The ERROR:

Notice: Undefined index: camara-de-vento in C:\wamp\www\index.php on line 126

Only line 126:

 if(isset($explode[1]) && in_array($categorias[$explode[1]], $categorias)){

That is: if there are [products] and the category entered (camera-of-wind) exists in the $ categories array, include the products page, if not, add the error.

As I said, everything works .. My idea is to treat the error page, which until then is being included, but also the error already informed.

    
asked by anonymous 02.05.2016 / 02:45

0 answers