Skip to content

Instantly share code, notes, and snippets.

@fdaciuk
Created September 20, 2013 00:55
Show Gist options
  • Save fdaciuk/6631997 to your computer and use it in GitHub Desktop.
Save fdaciuk/6631997 to your computer and use it in GitHub Desktop.
Chamada padrão para arquivos PHP
<!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