/    Sign up×
Community /Pin to ProfileBookmark

PHP Template Help

I’ve gotten advice on here before on my site, and I greatly appreciate it, but I’m at another stopping point.

I’m redoing a large, fairly dynamic website. There are 4 main categories, that the site is divided up into. The displayed pages are generated by the URL string which is similar to:

[url]http://www.mysite.com/subnav/page.php[/url]

The .htaccess redirects everything back to the index page. From the index, it pulls the subnav to display, builds the page with the correct styles, (different styles for each category), then includes the actual page (in this case, page.php). This seems to work really well so far, but I’m starting to run into a problem now.

On some pages, I want to include a special css file for only that page. This is a problem, because the page.php file is basically just included in the body part of the html.

I was thinking about doing an fopen on the page.php file. Then, if I set some variables for that page, they would be useable when the page is built.

Does this seem like a smart way to do this? Am I doing this completely backwards? Any advice would be appreciated. I’ll attach my index file as of now, which I think will explain what I’m talking about a little more.

Thanks, and any advice is greatly appreciated.

[code=php]<?php
$request = $_SERVER[‘REDIRECT_URL’];
$request = explode(‘/’, $request);

//Sets footer and main navbar for site.
$header = ‘template/header.php’;
$navbar = ‘template/navbar.php’;

//Check to see if there is a subnav, then get correct template file and set page to display.
if (!isset($request[2])) {
$template = ‘one_column_layout.php’;
$type = ‘one_column’;
$page = ‘pages/welcome.php’;
}else{
$template = ‘two_column_layout.php’;
$type = $request[1];
$subnav = ‘template/subnav/’ . $request[1] . ‘.php’;
$page = ‘pages/’. $request[2];
}
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” >
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<meta name=”author” content=”Jesse A. Inskeep” />
<meta name=”keywords” content=”Quad Cities, tourism, Quad City, visit, Davenport, Bettendorf, Moline, Rock Island” />
<meta name=”description” content=”Quad Cities Convention and Visitors Bureau Home Page.” />
<meta name=”robots” content=”all” />

<title>Quad Cities Convention &amp; Visitors Bureau</title>

<link rel=”stylesheet” type=”text/css” href=”/styles/styles.php?type=<?php echo $type; ?>” />
<script src=”/include/swfobject.js” type=”text/javascript”></script>

</head>

<body>

<div id=”main”>

<?php
include ‘template/header.php’;

if ($template == ‘one_column_layout.php’){
include ‘template/flash_header.php’;
}else{
include ‘template/picture_header.php’;
}

include ‘template/navbar.php’;

include ‘template/’ . $template;

include ‘template/footer.php’;
?>
</div>

</body>
</html>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 10.2006 — I personally see no problem with the idea behind it. the only problem is that you have to make sure that you check the vars in the url i.e. the subnav and page. I think hackers could use urls like that to execute their code on your server if you are not carefull. But I could be wrong.
×

Success!

Help @jesseainskeep spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...