- Código: Selecionar tudo
<?php
//CRIA UMA FUNÇÃO
function QueryString($get, $inicio, $pasta){
//verifica se $get existe
$get = (isset($get)) ? $get : '';
//remove os espaços antes e depois da string
$get = trim($get);
//remove tag php e html
$get = strip_tags($get);
//verifica se está vazio
if(empty($get)){
include("$pasta/$inicio");
}
//verifica se existe algum desses caracteres
elseif(eregi("http|www|.php|.asp|.net|.gif|.exe|.jpg|./", $get)){
include("$pasta/$inicio");
}
//verifica se o arquivo não existe
elseif(!file_exists("$pasta/$get.php")){
include("$pasta/$inicio");
}else{
//passando pelas verificações, ele dá o include
include("$pasta/$get.php");
}
}
?>
Update da Função
Recebi um email do Flavio Balmant, q apresentava uma notificação no script do query string, caso esteja acontecendo quem estiver o script, basta colocar um & no parametro $get. Mas na hora de usar a função é a mesma maneira.
Se vc estiver usando PHP 5.3 ou superior, tbm poderá causar um erro devido eregi, mas eu modifiquei trocando pelo preg_match, assim não ocorrendo esse problema. (Simplifiquei mais a função)
- Código: Selecionar tudo
<?php
function QueryString(&$get, $inicio, $pasta){
$get = (isset($get)) ? strip_tags(trim($get)) : '';
$regex = '/(http|www|.php|.asp|.net|.gif|.exe|.jpg|.html|.htm)/i';
$paginaHome = "{$pasta}/{$inicio}.php";
$paginaAtual = "{$pasta}/{$get}.php";
if(empty($get) || preg_match($regex, $get) || !file_exists($paginaAtual)){
include($paginaHome);
}else{
include($paginaAtual);
}
}
?>
//chama a função:
- Código: Selecionar tudo
<?php
QueryString($_GET['pagina'], 'home', 'arquivos');
?>
