• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Is this right? (PHP)

Ashed

New Member
PHP:
<?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:
 
PHP:
<?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:
 
Back
Top