Created
September 20, 2013 00:55
-
-
Save fdaciuk/6631997 to your computer and use it in GitHub Desktop.
Chamada padrão para arquivos PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="pt-br"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Teste</title> | |
</head> | |
<body> | |
<?php | |
// Verifica se o ?p foi passado na URL. Se foi, $p = o valor passado em ?p + .php (para dar include no arquivo) | |
// Senão, chama o arquivo home.php | |
$p = isset( $_GET['p'] ) ? $_GET['p'] . '.php' : 'home.php'; | |
// Pega o caminho do arquivo index.php | |
$url = dirname( __FILE__ ); | |
// Verifica se o arquivo chamado na URL existe. Ex.: | |
// Se for passado na URL ?p=sobre, vai verificar se existe um arquivo sobre.php no mesmo caminho desse index.php | |
$file_p_exists = file_exists( "{$url}/{$p}" ); | |
// Inclui o arquivo se existir. Senão, inclui o arquivo 404.php. | |
include ( $file_p_exists ) ? "{$p}" : "404.php"; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment