I have this code in a vars.php document to implement a friendly url:
<?php
//var_dump($_SERVER);
function parse_path() {
$path = array();
if (isset($_SERVER['REQUEST_URI'])) {
$request_path = explode('?', $_SERVER['REQUEST_URI']);
$path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
$path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
$path['call'] = utf8_decode($path['call_utf8']);
if ($path['call'] == basename($_SERVER['PHP_SELF'])) {
$path['call'] = '';
}
$path['call_parts'] = explode('/', $path['call']);
$path['query_utf8'] = urldecode($request_path[1]);
$path['query'] = utf8_decode(urldecode($request_path[1]));
$vars = explode('&', $path['query']);
foreach ($vars as $var) {
$t = explode('=', $var);
$path['query_vars'][$t[0]] = $t[1];
}
}
return $path;
}
$path_info = parse_path();
echo '<pre>'.print_r($path_info, true).'</pre>';
?>
<?php
switch($path_info['call_parts'][0]) {
case 'aempresa': include 'aempresa.php';
break;
case 'contato': include 'contato.php';
break;
case 'cumeeiras': include 'cumeeiras.php';
break;
case 'informacoes-tecnicas': include 'informacoes_tecnicas.php';
break;
case 'orcamento': include 'orcamento.php';
break;
case 'telha-ondulada-natural': include 'telha_ondulada_natural.php';
break;
case 'telha-pre-pintada': include 'telha_pre_pintada.php';
break;
case 'telha-termoacustica-semi-sanduiche': include 'telha_termoacustica_semi_sanduiche.php';
break;
case 'telha-trapezoidal-natural': include 'telha_trapezoidal_natural.php';
break;
case 'telhas-termoacusticas-sanduiche': include 'telhas_termoacusticas_sanduiche.php';
break;
case 'vantagens': include 'vantagens.php';
break;
default:
include 'index.php';
}
?>
However, you are printing the following error:
Fatal error: Can not redeclare parse_path () (previously declared in /var/www/html/formaremetais.com.br/web/teste/vars.php:4) in /var/www/html/formaremetais.com. br / web / test / vars.php on line 4
Address for review: link
Include code on all pages of the site using require
Note: the site is not separated in includes.
But the above error is occurring.
I need some help to fix this bug and find out what's going on. Thank you.