View Full Version : Help with PHP Includes?
anhedonia
February 16th, 2004, 20:52
Hi, I'm just having some problems with PHP Includes..
I am using this code to load the starting page:
<?if ($page != "") { include("http://www.trixabelle.com/pages/".$page.".html");} else {include 'http://www.trixabelle.com/pages/main.html';}?>
And this code to make the content pages load into that space:
<a href="http://www.trixabelle.com/index.php?page=toolkit/index">
But the content pages won't load. Am I doing something horribly wrong? I wouldn't really know because I'm new to PHP. Thanks.
keith
February 16th, 2004, 21:12
it'd make more sense to include php -- rather than html -- files, and to use the root path rather than the "http://" location.
here's a good way to do it:
put all your pages in a directory called /pages/ (http://www.trixabelle.com/pages/)... so if you'd want http://www.trixabelle.com/index.php?page=contact, create a file called /pages/contact.php (no header or footer info!).
also create a /pages/index.php file for your default page and /pages/error.php to handle nosey visitors...
then have your index.php file look like so:
<html>
<head>
<title></title>
</head>
<body>
<?php
if (!isset($_GET['page']))
include "pages/index.php";
elseif (file_exists("pages/" . $_GET['page'] . ".php"))
include "pages/" . $_GET['page'] . ".php";
else
include "pages/error.php";
?>
</body>
</html>
to have a unique title with each page, you can always set the filename to reflect your title... so a file called "send_us_feedback.php" will atomatically generate the title "Send us feedback" like so:
<html>
<head>
<title><?php
if (!isset($_GET['page']))
echo "Welcome";
elseif (file_exists("pages/" . $_GET['page'] . ".php"))
echo ucfirst(str_replace("_", " ", $_GET['page']));
else
echo "Error!";
?></title>
</head>
...
just use underscores where you'd want spaces, and it'll do the rest. that's about as automatic as you can get without having a full database at your discretion, though the /pages/ directory could probably be considered a rudimentary database.
anhedonia
February 16th, 2004, 21:15
Thanks for your help, I will try that out now and let you know if I can get it to work. :classic2:
anhedonia
February 16th, 2004, 21:26
Ah cool! Thanks a lot, that code you posted works great. Thanks again.
keith
February 16th, 2004, 21:28
glad to help :cool:
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.