PDA

View Full Version : Is this right? (PHP)



Ashed
April 21st, 2004, 12:33
<?php
if (!isset($_GET['p'])) {
header("Location: index.php?p=news");
exit;
}
else {
if (isset($_GET['s'])) {
if (!file_exists("templates/".$_GET['p']."/".$_GET['s'].".ash")) {
header("Location: index.php?p=404_error");
exit;
}
else {
include("templates/header.ash");
include("templates/".$_GET['p']."/".$_GET['s'].".ash");
include("templates/footer.ash");
}
}
else {
if (!file_exists("templates/".$_GET['p']."/index.ash")) {
header("Location: index.php?p=404_error");
exit;
}
else {
include("templates/header.ash");
include("templates/".$_GET['p']."/index.ash");
include("templates/footer.ash");
}
}
}
?>
I don't know PHP that well but does this look alright? p are the main pages while s are p's subpages. Is there a way to make it shorter? :frown2:

TheSpaceDude
April 23rd, 2004, 19:26
<?php
define('DOMAIN_NAME', 'http://www.yourdomain.com');

if (empty($_GET['p']))
{
header('Location: ' . DOMAIN_NAME . '/index.php?p=news');
exit;
}

$path = 'templates/' . baseName($_GET['p']);
$path .= empty($_GET['s']) ? 'index.ash' : '/' . baseName($_GET['s']) . '.ash';

if (!file_exists($path))
{
header('Location: ' . DOMAIN_NAME . '/index.php?p=404_error');
exit;
}

include 'templates/header.ash';
include $path;
include 'templates/footer.ash';
?>

That should do it :cool2: