PDA

View Full Version : Site Templating System Using PHP - Version 1


IH-James
13-06-2004, 05:36 PM
Ever wanted all pages on your web site to have exactly the same layout? Well now you can with this useful tutorial!

This tutorial uses only one PHP file (index.php) to display the entire contents of your web site. The actual textual content of your site will be read from basic text files. This means that if you change the look of the one php file, all pages on the site will be automatically updated with this new design!

An example of this tutorial can be viewed here (http://www.infernoforums.com/tutorials/templatesys/v1/index.php).

Step 1. Create a page, called index.php with the following contents:
<?php

/* The variable below is an array of valid pages.
When you add a new page, it must be added to this array.
*/
$validPages = array(
'about',
'contact',
'anotherPage'
);

?>
<html>
<head>
<title>InfernoForums Template System Tutorial - Version 1</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td colspan="2"><a href="http://infernoforums.com/index.php?showtopic=143%20">InfernoForums Template System Tutorial
</a> <hr></td>
</tr>
<tr>
<td width="150"><ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?p=about">About Us</a></li>
<li><a href="index.php?p=contact">Contact Us </a></li>
</ul></td>
<td align="left" valign="top">
<?php
if (isset($_GET['p']) && in_array($_GET['p'], $validPages) && file_exists("includes/" . $_GET['p'] . ".txt")) {
// a page has been specified and is a valid option, and the required file exists
// load content from relevant text file
include("includes/" . $_GET['p'] . ".txt");
} else {
// no page specified -> load content from default.txt
include("includes/default.txt");
}
?>
</td>
</tr>
<tr align="center">
<td colspan="2"><hr>
Footer Here <br>Copyright 2004 YourCompany.com </td>
</tr>
</table>
</body>
</html>You can customize this file later - for now keep it the same until you understand how things work.

Step 2. Create the content (.txt) files for your site:
This tutorial assumes that all .txt files are in a subfolder called includes.
In the includes folder create a file called default.txt. Here is my sample default.txt
Welcome to our web site!<br>
This page is under construction.
Now create another text file for every other page that you wish to have on your site. This tutorial assumes that you are going to have an About Us and also a Contact Us page. For each page you add, you must also add it to the $validPages variable at the top of the index.php file.

Notes:

You want all the text files to be a one word filename - eg about.txt. Things won't work properly if you use spaces and special characters in the filenames. I also recommend using all lower case in the filenames.
All links in these inlcluded pages will be with respect to where index.php file is located, because your content pages are being included into this file.
Step 3. Once you've created the default.txt, about.txt and contact.txt files, you are ready to give things a test. Upload the index.php file, as well as the includes directory (which should include about.txt and contact.txt) to your web server, then point your browser to index.php. You should see something similar to http://www.infernoforums.com/tutorials/tem...ys/v1/index.php (http://www.infernoforums.com/tutorials/templatesys/v1/index.php).

Step 4. Now that you have this basic setup working, it's time to customize the index.php file to suit your own liking. Just remember to put the block of php code wherever you want the textual page content to go. All links that you have on your site should be in the form of index.php?p=pagename, where the textual content of the pagename page is stored in includes/pagename.txt.

I hope this tutorial has been useful to you!

The source code for this tutorial is attached...

IH-James
14-06-2004, 06:05 AM
If you found this tutorial useful, please rate it at HotScripts:
http://www.hotscripts.com/Detailed/35616.html

Comments/Suggestions? Feel free to reply to this thread (Guests must register in order to post).

gooza
18-06-2004, 08:55 PM
When is Version 2 due to come? Excellent and easy to understand stuff you posted here James...

IH-James
19-06-2004, 08:47 AM
Originally posted by gooza@Jun 19 2004, 03:55 AM
When is Version 2 due to come? Excellent and easy to understand stuff you posted here James...
Glad to see you liked it!

I'll write it up very soon. I'm still thinking of ideas to add to it at the moment.

I suggest subscribing to this forum, and you'll receive an email when I make my next thread in this forum.

Regards,

Guest
20-06-2004, 07:19 PM
This One is S.U.P.E.R.
Dont know much about php and so this little helper was welcom...

IH-James
21-06-2004, 06:55 AM
Originally posted by Guest@Jun 21 2004, 02:19 AM
This One is S.U.P.E.R.
Dont know much about php and so this little helper was welcom...
Good to hear - glad it was helpful.

Version 2 isn't too far off - stay tuned!

Neil Washbrook
21-06-2004, 10:57 AM
Just what I was looking for :-) Done something similar using .asp and I am gradially converting to php. There was one issue I hit that I would be interested to know if you can enginneer a solution.

Take the situation where the include file is in a subdirectory and within it are relative links to graphics. If it is included as a template then the links dont work. Its a no brainer obviously to change the links to being non relative but its just an additional complexity when publishing articles submitted by other contributers to the web site.

IH-James
22-06-2004, 09:57 AM
Is this what you mean?

yoursite.com/index.php is the template page.
yoursite.com/includes/*.txt is where the content files are called.

The only way I can think of to combat this is to change the links to non relative when the .txt file is included. I'm not 100% sure how to do this but I'm sure it is possible. Let me know if you're interested in this as a solution, as I might include it in version 2 if I find that it's possible to do.

Cheers,

Guest
22-06-2004, 10:32 AM
Very interested - but the only way I can think of doing it is writing a parser as opposed to using the include. This starts to make it a little complicated.

IH-James
22-06-2004, 03:20 PM
Yeh. Maybe its worth just putting the include files in the same directory. After all, there is only one php file in the directory, and a few .txt files wouldn't hurt anyone.

gooza
22-06-2004, 09:53 PM
I had the same problem but it worked for me when I placed images folder into the root. It looked like this:

http://www.mypage.com/includes/
http://www.mypage.com/images/

All img tags worked fine although the images were outside the 'includes' folder... All images on all included pages were with simple tag like images/pic1.jpg.
Just to mention that I used .php pages insted of .txt in includes folder...

IH-James
23-06-2004, 03:33 AM
Yes all links on the included page will be with respect to where index.php file is located, because your content pages are being included into this file.

As gooza said, you can use any extension you wish isntead of *.txt - it doesn't make any difference.

ichitaka
07-07-2004, 10:28 AM
Originally posted by IH-James@Jun 14 2004, 12:36 AM
Ever wanted all pages on your web site to have exactly the same layout? Well now you can with this useful tutorial!

This tutorial uses only one PHP file (index.php) to display the entire contents of your web site. The actual textual content of your site will be read from basic text files. This means that if you change the look of the one php file, all pages on the site will be automatically updated with this new design!

An example of this tutorial can be viewed here (http://www.infernoforums.com/tutorials/templatesys/v1/index.php).

Step 1. Create a page, called index.php with the following contents:
</div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>HTML </td></tr><tr><td id='CODE'><html>
<head>
<title>InfernoForums Template System Tutorial - Version 1</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td colspan="2"><a href="http://infernoforums.com/index.php?showtopic=143%20">InfernoForums Template System Tutorial
</a> <hr></td>
</tr>
<tr>
<td width="150"><ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?p=about">About Us</a></li>
<li><a href="index.php?p=contact">Contact Us </a></li>
</ul></td>
<td align="left" valign="top">
<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.txt");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".txt");
}?>
</td>
</tr>
<tr align="center">
<td colspan="2"><hr>
Footer Here <br>Copyright 2004 YourCompany.com </td>
</tr>
</table>
</body>
</html></td></tr></table><div class='postcolor'>You can customize this file later - for now keep it the same until you understand how things work.

Step 2. Create the content (.txt) files for your site:
This tutorial assumes that all .txt files are in a subfolder called includes.
In the includes folder create a file called default.txt. Here is my sample default.txt
</div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>HTML </td></tr><tr><td id='CODE'>Welcome to our web site!<br>
This page is under construction.</td></tr></table><div class='postcolor'>Now create another text file for every other page that you wish to have on your site. This tutorial assumes that you are going to have an About Us and also a Contact Us page.

Notes: You want all the text files to be a one word filename - eg about.txt. Things won't work properly if you use spaces and special characters in the filenames. I also recommend using all lower case in the filenames.
All links in these inlcluded pages will be with respect to where index.php file is located, because your content pages are being included into this file.
Step 3. Once you've created the default.txt, about.txt and contact.txt files, you are ready to give things a test. Upload the index.php file, as well as the includes directory (which should include about.txt and contact.txt) to your web server, then point your browser to index.php. You should see something similar to http://www.infernoforums.com/tutorials/tem...ys/v1/index.php (http://www.infernoforums.com/tutorials/templatesys/v1/index.php).

Step 4. Now that you have this basic setup working, it's time to customize the index.php file to suit your own liking. Just remember to put the block of php code wherever you want the textual page content to go. All links that you have on your site should be in the form of index.php?p=pagename, where the textual content of the pagename page is stored in includes/pagename.txt.

I hope this tutorial has been useful to you!

Stay tuned, as next week I will show you how to extend this template system to include more advanced features.

The source code for this tutorial is attached...
:D :D :D :lol: :lol: :lol: :D :D :D
Thank you so much.... this (below) tutorial really works

Guest
08-07-2004, 02:53 PM
If I have modules like Guestbook nor News in folder modules, how to make my links.

Scema:
root directory -> modules directory -> guestbook

LCM
08-07-2004, 03:06 PM
If I have subdir in includes dir, how to make the links?

root dir -> includes dir -> subinc dir

Link to includes dir: index.php?p=about

LCM
08-07-2004, 03:11 PM
If I have subdir in includes directory, how to makes the links?


root dir -> includes dir -> subinc dir

IH-James
09-07-2004, 11:08 AM
As I said earlier:
all links on the included page will be with respect to where index.php file is located, because your content pages are being included into this file.
LCM, are you referring to having the included .txt files in a subdirectory of the includes folder? Could you please provide a little more information - I don't quite understand what you mean.

Cheers

LCM
14-07-2004, 12:13 PM
Yup
If I have moved:
includes/about.txt [move to]--> includes/about/about.txt
includes/contact.txt [move to]--> includes/contact/contact.txt

How to call that files?

gooza
18-07-2004, 07:45 PM
Originally posted by LCM@Jul 14 2004, 07:13 PM
Yup
If I have moved:
includes/about.txt&nbsp; [move to]-->&nbsp; includes/about/about.txt
includes/contact.txt&nbsp; [move to]-->&nbsp; includes/contact/contact.txt

How to call that files?
Just do it the same way you said in your post "includes/about/about.txt" although I see not much logic behind it...

gooza
18-07-2004, 07:56 PM
:huh: Maybe I'm going off-topic but I am trying to solve a problem. I am doing a page that contains some products and on that page there are thumbnails of the products with a hyperlink to a description page for each one of them. When you click on any product image you are taken to description page where, besides the description, there is also larger image (larger than thumbnail) of the product.
Now lot me describe what I need to do:
1. How can I set the thumbnails automatically, ie. how to enter variable int the <img> tag so it will recognize what photo to load from images folder...
2. On the description page how to set the large image to be laoded with a refference from the pagename: if a page is called product1.php then how to load image into it with the name product1.jpg without manualy entering location of the image?

Thx

IH-James
19-07-2004, 01:41 AM
LCM,

Change
<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.txt");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".txt");
}?> to
<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.txt");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . "/" . $_GET['p'] . ".txt");
}?>
ie the 2nd last line now searches in includes/pagename/pagename.txt, where pagename is the value of p in index.php?p=pagename.

LCM
20-07-2004, 08:22 AM
work! :)
Now I have change all the .txt file to .php. And change the content script to:
<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.php");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . "/" . $_GET['p'] . ".php");
}?>

In contact page (includes/contact/contact.php) I have litle PHP feedback script using mail() function.
e.g:
<?php
if (!isset($_GET['act'] == 'send'))
{
$comment=$_POST['comment'];
mail($var1, $var2, $comment);
}
else
{
echo "<form method=post action=\"?act=send\">";
echo "<textarea name=comment></textarea>";
echo "<input type=submit value=Submit>";
echo "</form>";
}

When I click Submit it will be call ?act=send
but it can run
how to fixed it?

IH-James
22-07-2004, 03:26 AM
Don't you want it to say:

<?php
if (isset($_GET['act'] == 'send'))
{
$comment=$_POST['comment'];
mail($var1, $var2, $comment);
}
else
{
echo "<form method=post action=\"?act=send\">";
echo "<textarea name=comment></textarea>";
echo "<input type=submit value=Submit>";
echo "</form>";
}
ie if act=send then mail to form, else print the form onto the web page.

Instinct
28-07-2004, 10:44 AM
On the description page how to set the large image to be laoded with a refference from the pagename: if a page is called product1.php then how to load image into it with the name product1.jpg without manualy entering location of the image?

make file called call.php
insert this code :

<?php
if (!isset($_GET['productid'])) {
echo " No Product Found "; // displayed if no product key submitted to page
} else { ?>
<html>
<body>
<?php
echo "<img src=\"images/".$_GET['productid'];
echo ".jpg\">";
// pictures should have same name as the product id
// ie. $productid=juicy_chicken image url should be images/juicy_chicken.jpg
}
?>
</body>
</html>

Only image tag has been placed, description can be inserted using the print() or other echo tags.

If i'm wrong, i'm wrong. :P Get back to me if this helped.(or if it didnt)

EDIT : TESTED OK!

gooza
29-07-2004, 10:28 PM
It works!!! Thx man!!! :D

Here's another one for you all, similar to LCM's last problem:

Several brands of with several models:
How to define link and script to call something like

echo "<img src=\"images/ .$_GET['brand'] . /".$_GET['model'] . ".gif\">";

i tried with brand=brand1&?model=1 in link

does NOT work... :rolleyes:

IH-James
30-07-2004, 03:18 AM
Gooza,

You've got the right idea, but your syntax isn't quite correct. Use:
echo "<img src=\"images/" .$_GET['brand'] . "/" . $_GET['model'] . ".gif\">";
Then you can have call.php?brand=apple&model=ipod which will load images/apple/ipod.gif.

That should do the trick.

Cheers,

Instinct
30-07-2004, 09:00 AM
Nicely put, glad i could help a lil :)

now with a bit of creativity you could use the same variables ($brand and $model) to call you data and BOOM! we're talkin dynamic baby! hehe

Instinct
30-07-2004, 09:35 AM
LCM :

Heres an edit of the contact script you tried to use.... Hope it works. I will explain the changes if u wish.

<html>
<body>
<?php
if($submit!="" && $var1!="" && $var2!=="" && $comment!=="") {
$var1 = "something";
$var2 = "something else";
$comment = $_POST[comment];
echo ($var1, $var2, $comment);
} else {
echo "<form method=post action=filename.php>";
echo "<textarea name=comment></textarea>";
echo "<input type=submit value=Submit>";
echo "</form>";
}
?>
</body>
</html>

LCM
30-07-2004, 01:13 PM
Yeah.... :D it's work.... I luv u ALL..... :*

Instinct
30-07-2004, 03:46 PM
Glad to help, and thank you IH-James for taking the time to actually write a tutorial and provide support and assistance to users.

Jst an off topic comment : Nice work InfernoHost crew and to the users, keep learning and askin, hehe

Ciao ciao :P

IH-James
31-07-2004, 03:56 AM
No problems - that's why I wrote the tutorial. To encourage community based learning around here.

I think asking others is the best way to learn, so I thought I'd try and encourage it.

Any ideas for that feature(s) to add for an improved version 2 tutorial, or any other tutorial suggestions are welcome.

Cheers,

Instinct
31-07-2004, 11:12 AM
i could knock up a few if u wish.... let me know... i'll get back to ya with ideas for the next version.

ciao ciao

IH-James
01-08-2004, 04:12 PM
Instinct,

That'd be great if you wanted to add some tutorials. I'm sure the other users around here would appreciate it too.

If you contact me using this (http://www.infernohost.com.au/company/contact.php) page, we can discuss the options.

Cheers,

KI4BBO
02-08-2004, 03:23 PM
Thanks for the idea.. I was trying to think of a templating system and this got me started... its a neat idea, but can use some work... I think my version is better :)


You can see what I did here, http://ki4bbo.org

Whats different:
1. Mine uses a check-if-file-exists command, so it wont try to include a non-existing file, instead it will display an error message.

2. There is a different title on each page

3. Multiple themes, that can be selected by the user, and will keep the current page

4. Created a static footer/menu in another file for all themes

5. The included files extension is .php, instead .txt, that way people ownt be able to get the source of my stuff



Here is how I did the error message and if file_exists:
<?php
if (!isset($_GET['p'])) {
include("includes/index.php");
} else {
if (file_exists("includes/" . $_GET['p'] . ".php")) {
include("includes/" . $_GET['p'] . ".php");
} else {
echo ("Awww man, sorry, but that page just does not exist!<br><br> Hmmm.. Josh must have mucked up, either that or you did something :D");
}
}
?>


And the title:
<?php
if (!isset($_GET['p'])) {
echo("welcome");
} else {
if (file_exists("includes/" . $_GET['p'] . ".php")) {
echo($_GET['p']);
} else {
echo ("Page not found");
}
}
?>


And I did some other minor stuff.. but thats the main thing :)

So, what are you planning to do with version 2?

Instinct
02-08-2004, 07:01 PM
nice idea, but if the webmaster is linking the files up it mite not be needed, but overall a nice idea. :)

KI4BBO
02-08-2004, 08:43 PM
Yes, I know it might not be needed.. but if someone sees the url and starts playing around like ?p=admin etc, I dont want them to see some weird error telling them where my include directory is..

and, when I first was re-aranging my site, I hadn't done all the content yet, so some links where non-working.. and wanted to display a custom error


Josh

Instinct
03-08-2004, 06:15 AM
nice thinking hehe

must admit never even thawt of it before. :)
good job

IH-James
03-08-2004, 03:45 PM
KI4BBO,

Thanks for the tips - the check if file exists is a great idea. I may include that with the v2 tutorial if you don't mind?

Cheers,

KI4BBO
05-08-2004, 12:49 AM
Originally posted by IH-James@Aug 3 2004, 10:45 PM
KI4BBO,

Thanks for the tips - the check if file exists is a great idea. I may include that with the v2 tutorial if you don't mind?

Cheers,
sure you can include it :D Glad to help :)

Josh

gooza
08-08-2004, 06:19 PM
Once again off-topic but also part of the project I'm working on (actually 2 projects)...
I made simple script to calculate total price for the selected products in form of $price = ($product1+$product2+$productX...) (go Einstain!!!). Products are in the form as list items with structure: Product1 description > Product1 price...
Everything works fine and I get final result without problems. Problem is that I want to have also summary of all selected items on result page (ex. result.php). I tried but I can only display value (price) of item by using echo or print function and not the description.
How to get following on the result page with both description and the price (I know it can be done but not by me at this moment):

'You've selected following products:

Product1 description - 10$
Product2 description - 20$
Product3 description - 30$

Total - 60$'

All of your previous advices I already used and everything is ok. Once again thank you for always posting your replies fast...

P.S.: As soon as I finish I'll post the addresses of the projects...

Instinct
09-08-2004, 06:17 AM
are you using a database backbone? :huh:
i can picture how to do it using MySQL for example but it too early in the morning to try without a db. :rolleyes:

IH-James
09-08-2004, 02:55 PM
gooza,

I don't quite understand how you're storing your product details.
Products are in the form as list items with structure: Product1 description > Product1 price...
Can you give me some more specific code so I can understand how you've done this more?

Hopefully then I'll be able to help you.

Cheers,

gooza
09-08-2004, 05:44 PM
Here is the form from where I display products:

'<form action="index.php?p=result" method=post>
Motherboard
<select name="motherboard">
<option value="0" selected>- Choose product - </option>
<option value="120">Asus A7N8X-E DeLuxe</option>
<option value="50">MSI Blabla</option>
</select>


Processor
<select name="processor">
<option value="0" selected>- Choose product - </option>
<option value="6">Intel MMX 233MHz</option>
<option value="50">AMD something</option>
</select>


Memory
<select name="memory">
<option value="0" selected>- Choose product - </option>
<option value="120">128MB</option>
<option value="50">512MB</option>
</select>







<input type="submit" name="submit" value="Calculate the price">
</form>'

I left only 3 types of products... As you can see form is being processed relative to template (index.php?p=result which helps me keep the same layout (template) - what I've learned from your tutorial.

Second page is result.php and here is the code in it:
'<?php

function configuration($motherboard, $processor, $memory) {

$calc = ($motherboard+$processor+$memory);

$price = number_format($calc, 2, '.', ',');

print "Chosen config costs $price € ...";

}

configuration($motherboard, $processor, $memory);

?>'

As a result it prints only the total price and would like to also have summary of chosen products like:
You've selected

Asus A7N8X-E DeLuxe 120
AMD something 50
128MB 120

Total price is 290


I am learning more an dmore of PHP but this gives me headache. Also I know nothing about MySQL but I am starting to read some books in order to learn it because PHP is much more complete combined with MySQL...

Thanks guys,

Bojan

Instinct
10-08-2004, 06:05 AM
Maybe that should be my first tutorial for InfernoForums.... introduction to MySQL with PHP....

As for your form i would suggest using checkboxes or using the product name as value="" instead of the price. Then on the result page use ifs to work out the price depending on which items are selected.

For example if $processor is valued as "intel1" (instead of the price 6 or whatever)(will probly have to use full names in identifying each term so it can be displayed afterwards) then the result page can be asked to check :

$processor = $_GET[processor];
if ($processor=="AnotherOption") {
$processorprice = (1 000 000);
} elseif &nbsp;($processor=="Intel1") {
$processorprice = (6) &nbsp;};
// do same with all other submissions
// then....
function configuration($motherboard, $processor, $memory) {
$calc = ($motherboardprice+$processorprice+$memoryprice );
$price = number_format($calc, 2, '.', ',');
print "Chosen config costs $price € ...";
}
configuration($motherboard, $processor, $memory);
print "With current Specifications :";
print $motherboard;
print $processor;
print $memory;

gooza
10-08-2004, 08:15 PM
Maybe this will help because this is exactly what I tried to make:

http://www.comtel.co.yu/prezentacija/sastavi.asp


The page is not in English but you'll certainly get the idea...

Instinct
11-08-2004, 06:38 AM
ok firstly that page uses javascript for the id's of the choices in the drop boxes.... and secondly it is possible in php.

but rite now it too early in the morning and i got too much to do... i'll try get back to ya asap.

Maybe someone else can help ya in the meantime.

IH-James
11-08-2004, 04:56 PM
Gooza,

I've had a bit of a play and I think this should do what you're after:

The form page:
<form action="result.php" method=post>
Motherboard
<select name="motherboard">
<option value="None Selected" selected>- Choose product -
<option value="Asus A7N8X-E DeLuxe - $120">Asus A7N8X-E DeLuxe - $120
<option value="MSI Blabla - $50">MSI Blabla - $50
</select>
<br>
Processor
<select name="processor">
<option value="None Selected" selected>- Choose product -
<option value="Intel MMX 233MHz - $6">Intel MMX 233MHz - $6
<option value="AMD something - $50">AMD something - $50
</select>
<br>
Memory
<select name="memory">
<option value="None Selected" selected>- Choose product -
<option value="128MB - $120">128MB - $120
<option value="512MB - $50">512MB - $50
</select>
<br>
<br>
<p>
<input type="submit" name="submit" value="Calculate the price">
</form>
The Results page:
<?php
$motherboard = $_POST['motherboard'];
$processor = $_POST['processor'];
$memory = $_POST['memory'];

/* Obtain the prices of each product */
$motherboardPrice = substr( $motherboard, strpos($motherboard,"$")+1 ); /*Motherboard */
$processorPrice = substr( $processor, strpos($processor,"$")+1 ); /* Processor */
$memoryPrice = substr( $memory, strpos($memory,"$")+1 ); /* Processor */

/* Calculate total price */
$total = $motherboardPrice + $processorPrice + $memoryPrice;

/* Print out products selected */
echo("<p>You've Selected:

Motherboard: $motherboard
Processor: $processor
Memory: $memory");
/* Print out total price */
echo("<p>Total Price: $total");

?>
The script will only work if the value of each item in the select boxes is in the form Product Name - $price. This is because the price is read using all the remaining characters after the $ sign.

Please let me know if you need any further help.

Cheers,

gooza
12-08-2004, 10:57 PM
It works!!!!!!!!!

Instinct
12-08-2004, 11:06 PM
Well of course :) He is good! hehe

IH-James
13-08-2004, 08:00 AM
It works!!!!!!!!! Good to hear mate - glad I could help.

I look forward to seeing your site once you're ready to post the link.

James

IH-James
22-08-2004, 04:04 PM
Would anyone be interested if I redid this tutorial, this time using a MySQL (database) backend?

Using MySQL instead would have quite a few advantages over this version.

Of course achieving this is a bit more complicated, but it is well worth it in the end I would say.

Cheers,

gooza
02-09-2004, 10:41 PM
I know basics of MySQL but only as a user of thinghs that other people made. Also I know that there will be more people interested in reading your tutorial. ANother important thing is that anyone who needs additional info can simply post his problem on this forum and interact with the whole learning story... :P

IH-James
03-09-2004, 09:30 AM
I know basics of MySQL but only as a user of thinghs that other people made. Also I know that there will be more people interested in reading your tutorial. ANother important thing is that anyone who needs additional info can simply post his problem on this forum and interact with the whole learning story... :P
Thanks for your comments, gooza!

I'll make a final decision soon.

michael
20-09-2004, 02:49 PM
Would anyone be interested if I redid this tutorial, this time using a MySQL (database) backend?

I would like it very much if you shared a MySQL version of this example.

this is a very clean to the point and easily understood tutorial.

thank you for that!

shiftsrl
20-09-2004, 05:33 PM
Many thanks for the good tutorial. I've just a question. How can I make every page loads with his title and his metatags?

Instinct
20-09-2004, 09:09 PM
Many thanks for the good tutorial. I've just a question. How can I make every page loads with his title and his metatags?

So you want each page to load the content as stated in the tutorial but u want each content page to have it's own meta tags and page title?

The best way of doing this would to include this code in the beginning of your *.txt file :

<?php
$metakeyword="bla,bla,bla";
$pagetitle="title";
?>


and then change the main pages code to :


<html> <head> <title><?php echo $pagetitle; ?></title>
/* insert meta tags here */
</head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td colspan="2"><a href="http://infernoforums.com/index.php?showtopic=143%20">InfernoForums Template System Tutorial </a> <hr></td> </tr> <tr> <td width="150"><ul> <li><a href="index.php">Home</a></li> <li><a href="index.php?p=about">About Us</a></li> <li><a href="index.php?p=contact">Contact Us </a></li> </ul></td> <td align="left" valign="top"> <?php if (!isset($_GET['p'])) { // no page specified -> load content from default.txt include("includes/default.txt"); } else { // page specified -> load content from relevant text file include("includes/" . $_GET['p'] . ".txt"); }?> </td> </tr> <tr align="center"> <td colspan="2"><hr> Footer Here <br>Copyright 2004 YourCompany.com </td> </tr> </table> </body> </html>


IH-James please edit this post, i have very short time left online.... but thats the main idea that i would think of.

IH-James
21-09-2004, 12:16 PM
michael: thanks for the kind comments - I'll start on the tutorial very soon.

shiftsrl: The best way to achieve a thing such as this would be using mysql instead of files to read the page contents.

I will show you how to achieve this in the MySQL tutorial that I am planning on writing before the end of this week.

Do you have access to MySQL on your server?

James

shiftsrl
21-09-2004, 01:31 PM
michael: thanks for the kind comments - I'll start on the tutorial very soon.

shiftsrl: The best way to achieve a thing such as this would be using mysql instead of files to read the page contents.

I will show you how to achieve this in the MySQL tutorial that I am planning on writing before the end of this week.

Do you have access to MySQL on your server?

James

Hi James, I've access to MySQL so I could follow your tutorial. Basically, what I want to do is create a site where the layout is separated from the content. I'm actually using Mambo (http://www.mamboserver.com) for our main site, but mambo does'nt fit for another site (http://www.kog.it) I'm about to rework.

This tutorial is wonderful but I need that each page has it's own name and it's own metatags (keyword and description).

By the way, how this system works with the search engines?

shiftsrl
21-09-2004, 01:32 PM
So you want each page to load the content as stated in the tutorial but u want each content page to have it's own meta tags and page title?

The best way of doing this would to include this code in the beginning of your *.txt file :

<?php
$metakeyword="bla,bla,bla";
$pagetitle="title";
?>


and then change the main pages code to :


<html> <head> <title><?php echo $pagetitle; ?></title>
/* insert meta tags here */
</head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td colspan="2"><a href="http://infernoforums.com/index.php?showtopic=143%20">InfernoForums Template System Tutorial </a> <hr></td> </tr> <tr> <td width="150"><ul> <li><a href="index.php">Home</a></li> <li><a href="index.php?p=about">About Us</a></li> <li><a href="index.php?p=contact">Contact Us </a></li> </ul></td> <td align="left" valign="top"> <?php if (!isset($_GET['p'])) { // no page specified -> load content from default.txt include("includes/default.txt"); } else { // page specified -> load content from relevant text file include("includes/" . $_GET['p'] . ".txt"); }?> </td> </tr> <tr align="center"> <td colspan="2"><hr> Footer Here <br>Copyright 2004 YourCompany.com </td> </tr> </table> </body> </html>


IH-James please edit this post, i have very short time left online.... but thats the main idea that i would think of.

Thanks but the title doesn't show up :(

IH-James
22-09-2004, 04:25 AM
With regards to the MySQL template system, what aspects of each page would you want to be customised?

Currently I will include support for the following in the tutorial:
Page Title (for use in the <title> tag)
Page (<meta>) Keywords
Page (<meta>) Description
Page Main Content (somewhere in the <body> section)

Adding more fields than this isn't too hard, so if anyone requires more editable sections on each page then it won't be too hard to extend the idea.

James

shiftsrl
22-09-2004, 09:45 AM
With regards to the MySQL template system, what aspects of each page would you want to be customised?

Currently I will include support for the following in the tutorial:
Page Title (for use in the <title> tag)
Page (<meta>) Keywords
Page (<meta>) Description
Page Main Content (somewhere in the <body> section)

Adding more fields than this isn't too hard, so if anyone requires more editable sections on each page then it won't be too hard to extend the idea.

James

Initially I think that they suffice. Should be eventually interesting to have an option to include, for example, a "block" defined by the webmaster...

Instinct
23-09-2004, 06:12 PM
i agree with james....

my method doesnt seem to work, even on a completed version.... the easiest way i can imagine is using MySQL as james sed. Sorry bout the mix-up before. Too much coffee messed wit ya hed :P

IH-James
24-09-2004, 03:54 AM
Initially I think that they suffice. Should be eventually interesting to have an option to include, for example, a "block" defined by the webmaster...
May I ask what do you mean by a "block"?

Cheers

shiftsrl
24-09-2004, 07:53 AM
I've taken the term from Geeklog. A "block" is a block of html or php lines that do something and you can decide where to place this block on your page. A sort of include for php...

shiftsrl
24-09-2004, 04:22 PM
Hello, any news about your tutorial? :)

IH-James
24-09-2004, 06:21 PM
It's still in the works.

Expect it out sometime in the next few days.

Stay tuned!

shiftsrl
25-09-2004, 03:42 PM
Fantastic! I'll check back soon :)

Thanks again

shiftsrl
29-09-2004, 10:23 AM
One of the missing features I've seen in others CMS that use mysql and php to build a site, is the possibility to include a PHP file in the page. I have a page that has some php includes and when I've inserted the code, the php includes doesn't seem to be evaluated.

just to be more precise, what I need is the possibility to insert in a page the results given from an external php script. i would like to insert this instruction

<?php include("http://www.xxxxxx.xx/sunrise.php"); ?>

that give me back the sunrise time each time the page is loaded.

Instinct
07-10-2004, 11:24 AM
i always thawt that you couldn't inlclude any files from other sites other than your own....

i wuld suggest trying to get a copy of the code on your own server (easier)
or it can be included as an image but i believe this has to be allowed by code in the script.

i may be rong tho.

hackula
14-10-2004, 07:09 AM
This is fascinating! I am all for the SQL backend idea. It makes the possibilities endless.

Thank you very much.

Mr. H.

IH-James
15-10-2004, 12:22 AM
This is fascinating! I am all for the SQL backend idea. It makes the possibilities endless.

Thank you very much.

Mr. H.
Thanks for the kind comments!

The MySQL backend system isn't very far off at all now...

ocabeza
20-11-2004, 04:26 AM
Hi. I like this tutorial and the idea behind it.

I can't get it to work on my computer. It works when I upload it to my site.
I doesn't seem to like the php. It doesn't seem to run through the php code. When I look at the source from the browser, it shows the php code in there :confused:

Any ideas as to what settings I may have wrong? :confused: :confused:



Thanks!

I also can't wait to see the next version.

IH-James
20-11-2004, 04:39 AM
Hi there ocabeza - welcome to the forums!

Do you have a web server installed on your computer?

What OS are you using?

You need to install a web server (such as apache) on your computer, then install PHP too. Have you done this?

Cheers,

ocabeza
21-11-2004, 04:32 PM
Hi there ocabeza - welcome to the forums!

Do you have a web server installed on your computer?

What OS are you using?

You need to install a web server (such as apache) on your computer, then install PHP too. Have you done this?

Cheers,

Yes, I have WAMP5.1 (Apache 1.3.x. MySQL 4.x.x PHP 5.x.x) running on Windows XP.

IH-James
22-11-2004, 12:35 AM
Do any other PHP scripts work properly?

You can test it by making up a file called something like info.php wit hthe following contents:

<?php
phpinfo();
?>Let me know whether or not that outputs a whole lot of configuration information. If not, php is most probably not installed correctly.

gooza
24-11-2004, 03:56 AM
If you get php code on your page it could be that you did not use php tags ie <?php and ?>... :confused:

IH-James
30-11-2004, 03:32 PM
ocabeza,

Did you get it working in the end?

Rog
15-01-2005, 07:07 PM
Ever wanted all pages on your web site to have exactly the same layout? Well now you can with this useful tutorial!

This tutorial uses only one PHP file (index.php) to display the entire contents of your web site. The actual textual content of your site will be read from basic text files. This means that if you change the look of the one php file, all pages on the site will be automatically updated with this new design!



James, I have a series of images (maybe 40+) on a site that all click to a pop up window for the enlargement (popup.php?image=blockone). I was well on my way to recreating your solution in my own hacked way (my way the target page grabs the image based on the image name clicked) but have a slightly different problem. Each has a caption. Some long, some 2 words. Rather than have a single text file for each caption. I was thinking I would do one long text/php file and "if/else" work my way through it, to assign a value based on the image selected to $caption.

Does it make sense to do this this way? I can't get it working and need advise.
Thanks
Rog

IH-James
16-01-2005, 02:25 PM
Rog,

Welcome to the forums!

I would do something similar to what you mentioned.

I would have in the popup.php file some code that is similar to this:

switch ($_GET['image']) {
case "imageone":
$caption = 'image ones caption';
break;
case "imagetwo":
$caption = 'image twos caption';
break;
.
.
.
default:
$caption = 'no image found';
}


echo $caption;

Does this make sense?

Cheers,

Rog
16-01-2005, 09:35 PM
Rog,

Welcome to the forums!

I would do something similar to what you mentioned.

I would have in the popup.php file some code that is similar to this:

switch ($_GET['image']) {
case "imageone":
$caption = 'image ones caption';
break;
case "imagetwo":
$caption = 'image twos caption';
break;
.
.
.
default:
$caption = 'no image found';
}


echo $caption;

Does this make sense?

Cheers,

THANKS!

Yeah it does. I'm not really familiar with the ($_GET['image']) but I think the PHP bible will expain enought to get a grasp.

Could I make the list of variables an external file (meaning not part of the pop page)?

IH-James
17-01-2005, 12:02 AM
THANKS!

Yeah it does. I'm not really familiar with the ($_GET['image']) but I think the PHP bible will expain enought to get a grasp.The name of the URL variable is image (eg popup.php?image=blah). For example, with popup.php?var1=value1&var2=value2 you would use $_GET['var1'] and $_GET['var2'] to access the values of the variables.

Could I make the list of variables an external file (meaning not part of the pop page)?The simplest way to do this that I can think of is to have a separate caption file for each image, and just include the caption file for that specific image.

Alternatively you could use a MySQL database, which may however be overkill in this situation.

Cheers

Rog
17-01-2005, 10:04 PM
The name of the URL variable is image (eg popup.php?image=blah). For example, with popup.php?var1=value1&var2=value2 you would use $_GET['var1'] and $_GET['var2'] to access the values of the variables.
Cheers


This worked PERFECTLY. Thanks!

Rog

IH-James
18-01-2005, 05:22 AM
Glad to hear it Rog.

If you have any other questions please feel free to start a new thread.

Cheers,

Rog
16-02-2005, 05:09 PM
James, NOW I'm actually looking at using the site templating system that this thread is talking about.

I have my header as an include. It contains the links to css and js and also has the line <title><?php echo $page_title; ?></title>

Before the header include I have this line <?php $page_title = 'where i place the name of the page'; ?>

Oh, I have an include holding all my nav stuff.

The question. Should I throw all of these includes into the text files that are being loaded? Seems at this point I'd be just showing the <?php if!isset portion and having it grab everthing to build the page. Am I thinking ahead of this? Would it work?

The way I'm looking at the template system tutorial, it seems to be more getting the guts of the page and if it ween't for the various titles of different pages, I'd be there.

Thanks again
Rog

IH-James
16-02-2005, 05:18 PM
Rog,

I'm not quite sure what you're trying to achieve.

Is there any way you can elaborate things?

If I understand you, you're trying to set the value of $page_title before including the header, so that the different titles can be displayed. Correct?

What else are you trying to do?

Cheers,

Rog
17-02-2005, 08:22 PM
Basically you've got it. I try to keep the page titles descriptive to the page. If you've ever saved a buch of bookmarks to a site and had them all say the same darn thing, well, that's no fun.

I throw a value for the title before the header include. (As I look at session stuff and cookies, I realize I'm headed for trouble. The top of that page is getting crowded.)

<?php $page_title = 'where I place the name of the page'; ?>

Then the header include has a <title><?php echo $page_title; ?></title>

Driving home last night I was thinking back to your code and thinking about the other problem I had with images and captions, I started to think maybe if I were to do it in a similar fashion?

<li><a href="index.php?p=about&page_title=About Us ">About Us</a></li>

I probably would not need my code about the page_title in the top of the page (but still keeping it in the header include).

But is that a practical way to do this?

Thanks again James.

Rog

Instinct
09-03-2005, 02:24 PM
heya Rog,
i dont seem to see why you would put a php tag at the top of the page... seems like a lot of work just for it to show up in the <title></title> section.... wouldnt it be easier to edit every page?

ok heres for the dynamic area, because lets face it, everyone wants to be dynamic...

i wuld personally create an include file let it be titles.inc or titles.php...
in that file i would list a bunch of variables... sorta like this...

<?php
if ( $page == file1 ) { echo Title for file 1; }
else if ( $page == file2 ) { echo Title for file 2; }
else if ( $page == file3 .... etc u get the point.
else {echo Error;}
?>

and include it into your template system where the title would be eg
<title><?php include('titles.inc'); ?></title>
and if you use $page to get the name of your file this would work great....



*EDIT - after reading Jame's previous post i've realised his way is neater... and probably better to use a method like his previously suggested one.
**EDIT (again) - after reading up on the 'switch' method it works exectly the same but is just neater :)

N-Sanity
21-03-2005, 02:41 AM
Im still a php newbie lol:D
And here is my dilemma... :confused:
I have a main iframe on my site, right in the center of course... and when i wrote the links, i obviously put target="Name Of My Frame".
It does work, but a little wierdly.
I get my .txt file displayed alright, but under it my whole page repeats :confused:
And btw, how do u select a target location for the default 8|...
Dude plz mail back ur response to n.saneman@gmail.com.
Thnx in advance :D

prjktdtnt
08-04-2005, 09:57 AM
Hey totally awsome script. I have used it myself on one of my client's websites. http://aloha.shawnster.net . Its hosted on my own domain because its my dad's site lol. Ok well it is used for the "Pictures" area. I am possibly gonna use it for another website but I was thinking maybe to wait for v2 to come out because I love using a MySQL backend. Much easier to manage if you have the right admin scripts. well carry on and whatnot.

-Shawn aka Trash
-Projekt DotNet Designs
-http://www.shawnster.net

IH-James
08-04-2005, 10:09 AM
Glad I could help Shawn!

I agree, MySQL backends are much more easily maintainable once set up.

Cheers,

James

prjktdtnt
09-04-2005, 08:21 AM
i cant wait for that next tutorial to come out. I would really like to see what you do with it.

N-Sanity
14-04-2005, 07:10 PM
Hey guys, its me posting again.
In one of the pages in this thread, you solved the problem of multiple folders and finding the included files inside of them.
Say i want to make the same thing, but then you have to put all ur texts in into however many subfolders you want to use.
for example you have

{Main Includes Folder:
Pruducts:
Brand:
Versace:
Versace.txt
Pages:
About:
About.txt
Contact:
Contact.txt}

then u have to make another folder in pages, ie a second Pages, so that u have a 3 folder name when you make the link.

But i want it to only have a 2 folder name lol, so im a little stumped. Plz Help Solve.

prjktdtnt
15-04-2005, 08:25 AM
ok here we go hopefully this will solve your cased problem.
arguments my friend, get arguments!

yourscript.php?dir=products&subdir1=brands&subdir2=versace&file=versace

<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.txt");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['dir'] . "/" . $_GET['subdir1'] . "/" $_GET['subdir2'] . "/" . $_GET['file'] . ".extension");
}?>

if that isnt what you were looking for then im sorry but if it was then yeay.
-Shawn aka "Trash"

N-Sanity
15-04-2005, 10:50 PM
Nope, didnt help at all.
You dont get what i mean.
See with v1 and ur version, u have to have that many subdirs right?
say i want to say pages>products>versace>jeans>LowCutJeans.txt, but for another link i just wana say pages>about.txt.
In this case, so far i have to put the about into someplace like this:
pages>about>about>about>about.txt
You get my drift now?

IH-James
16-04-2005, 02:05 AM
Hi N-Sanity,

I'd do something like this:
(url -> included directory)
page.php?p=about -> includes/about.txt
page.php?c1=products&p=index -> includes/products/index.txt
page.php?c1=products&c2=versace&c3=jeans&p=lowcut -> includes/products/versace/jeans/lowcut.txt

How does that sound?

If it sounds useful, I'll try and knock up the code for you.

James

N-Sanity
17-04-2005, 04:08 PM
Not really.. no... cuz people can see my code, and im extremely picky about that...lol dont laugh but uum yeah....

Oh, btw, if u guys wana see what im working on right now, check out:

<a href="www.thechaostempletestarea.wz.cz">The Chaos Temple Clan Site<a>

Hope you like it...
btw, still looking for a solution here...

prjktdtnt
20-04-2005, 06:59 AM
ya know it may not be extremely usefull to "N" but i might be able to use a system such as that...doesnt bug me none at the moment really.

N-Sanity
22-04-2005, 08:14 PM
UUm, ok first of all dudes, u have an error on page.
line 2
char 1
type: syntax

N-Sanity
22-04-2005, 08:47 PM
Crap.. forgot to get to my point ;)

Anyway, i had an idea for a enw templating system, but i need help.
I was thinking of doing the following:


say this is wats o my webserver:

index.php

Skin_01:
Header.jpg
Background.jpg
Footer.jpg

Skin_02:
Header.jpg
Background.jpg
Footer.jpg
pages:
home.txt

anyway, so the files in folders skin_01 and _02 are named the same, but are absolutely different.(theyr dimensions though are the same...)
now, i need to make a global variable, called $Skin, which will hold the name of the folder.
Then i need to make a page that changes it.
Final thing is to implement it.
i was thinking something along the lines of:
<img src="$Skin/image.jpg">
so, that way i can have as many skins as needed, but the names pretty much stay the same.
The tables in whicht he images are also stay the same.
Plz make it happen ppl.

prjktdtnt
22-04-2005, 09:43 PM
ok the following Idea is inspired by MOS (Mambo Open Source CMS) but what you would do is make a template.css that had all your imaged then use div id's (div id=blank, and in the css it would be defined:
#blank{
your css code here
}
)

and then you would just have the <?php include($Skin/template.css); ?>
i know that may not be proper syntax (still learning) but that would be the basis of it and then make sure your pages had the same data in the same type of div id's and other forms of classes so that you would only be changing layout and color not data. wouldnt be entirely sure how to define $Skin though through changes (cookies vs Get method);
im sure IH-James might know that one

N-Sanity
22-04-2005, 10:22 PM
nonono man, not like that, the folder name is a variable, i dun need no goddam css
just this idea lol
i know its easy to do in php
just have no idea how to.

IH-James
20-05-2005, 03:52 AM
prjktdtnt,

That is not a bad idea - including different .css files depending on the skin selected.

I would think you are correct in saying that cookies would probably be necessary.

The cookie could store the name of the user's desired skin.

James

prjktdtnt
25-05-2005, 06:20 PM
why thankyou IH-James I'm glad that I may, in some small way, inspired progress in the design. Cant wait for the next release.
-Trash

datawizard
02-06-2005, 04:05 AM
Hi all , I found this handly php script and its perfect for what im aiming to do with my update on my website , its better than using an I-frame hehehe
anyhow couple things about it that i was wondering if i could get some help with , first of all is there anyway to set the script up so that it can acess more than just one type of file ,
i changed it from this -->
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.php");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".php");

to this --->
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.php");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".php" .$_GET['p'].''.htm'');

and i get errors when i run page , any clue what im doing wrong ?

and last question i have, is there a method that can be used so that i can keep images in its own folder instead of the same dir as the index.php file is , reason for this is id like to keep some sense of order :D

IH-James
02-06-2005, 07:45 AM
Datawizard, welcome to the forums!

The line should read:
include("includes/" . $_GET['p'] . ".php" . $_GET['p'].'.htm');
You had your syntax slightly wrong. However I am not quite sure what you wish to achieve here, as the line above would, for a ?p=pageName, do:
include("includes/pageName.php.pageName.htm");
which i'm sure is not what you are trying to achieve.

With regards to images, you could store them all in a folder called images. Then on all your includes/*.php, when you link to an image the links would be of the form:
<img src="images/img.gif">
where the images directory is in the same folder as your includes (root) directory.
eg

/includes/
/images/
index.php

would all be in the same directory.

Please specify exactly what you are trying to achieve so I can help you better.

Cheers,

James

datawizard
02-06-2005, 08:35 AM
Hi James and thank you for the greets,
The picture explanation works perfectly, TY
my top question , how can you set up so that u can use diffrent file formats , like say example in the script you have it set to
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.php");

but in the Includes folder there is index.PHP and another file called test.HTM how can you call up the test file up also without getting error
see what im askin??

also a little off subject, i was reading thru this thread and i ran across part for putting titles(page10 of this thread) for your pages and this is what i have for my titles.php

if ( $page == default.php ) { echo Home; }
else if ( $page == order.php ) { echo Order; }
else if ( $page == contact.php ) { echo Contact; }
else {echo Error;}

and in between the TITLE tags in the index.php i have
include('titles.php');

and i get a parsing error showing in the title of my browser
any idea whats wrong there?

Again thank you for the quick reply and if you are still planning on releasing ver 2 of this script , i am looking forward to it and will be more than happy to test drive it for ya ;)
I happen to have 2 places that i can run php stuff , one being my website and another is my personal home puter as i have that set up as a personal webserver with PHPDEV.

IH-James
02-06-2005, 08:40 AM
but in the Includes folder there is index.PHP and another file called test.HTM how can you call up the test file up also without getting error
see what im askin??
What is in the includes/index.php file? Also, what do you mean by different file formats.

I'm glad the images solution worked.


if ( $page == default.php ) { echo Home; }
else if ( $page == order.php ) { echo Order; }
else if ( $page == contact.php ) { echo Contact; }
else {echo Error;}

and in between the TITLE tags in the index.php i have
include('titles.php');

and i get a parsing error showing in the title of my browser
any idea whats wrong there?
try:
if ( $page == 'default.php' ) { echo 'Home'; }
else if ( $page == 'order.php' ) { echo 'Order'; }
else if ( $page == 'contact.php' ) { echo 'Contact'; }
else {echo 'Error';}
ie all strings need to be surrounded by quotation marks.

Cheers

datawizard
02-06-2005, 08:59 AM
My main index.php has this
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/default.php");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".php");
}?>
and in my includes folder there are several files there using the PHP extension
now I have included a file there called test.HTM , thats what i mean by using diffrent file formats , IE *.php, *.htm *.XML exctra Is there a way to set the script so that it can support calling up diffrent file types, I hope this is a little clearer put , hehehe

also on the Titles
i have this , had a mistake besides not having the quotes( DOH shoulda known better) i also didnt have path to files so now it looks like this

if ( $page == 'includes/default.php' ) { echo 'Home'; }
else if ( $page == 'includes/order.php' ) { echo 'Order'; }
else if ( $page == 'includes/contact.php' ) { echo 'Contact'; }
else {echo 'Error im not here';}

the script is reading properly except its showing me --> Error im not here message. so some reason its not finding the pages there and the 3 files are in the includes dir :confused:

Instinct
05-07-2005, 02:38 PM
hey all i'm baq, and takin a break from the 2 cms's i'm building, in order to help you ppl like some others helped me out here a while ago.

firstly datawizard, since you're using 'p' as your get variable ure include file should look for the value of that and not the value of 'page'

another thing i learnt in here is keep your stuff neat, so instead of using if and if else we will be using switches.

includes/title.php :

$page = $_GET['p']; // Declaring the page Variable
switch ($page) { // Starting our switch command
case "Home" : // If page = home
echo "Welcome Home";
break; // Allow for next condition
case "Pictures" : // if page = pictures
echo "Enjoy my pictures";
break;
default : // If page is not one of the ones set in here
echo "error!"
} // End Switch command


dont forget to include this into your php page like so :

index.php :

<title><?php include('includes/title.php'); ?></title>


This should work 100% if not just reply and i'll do my best to check in asap.

Keep up the good work, keep the passion, and remember those who helped you so u knw how to help others in good time. Long live the internet ;)

datawizard
05-07-2005, 08:28 PM
Howdy Instinct, I tried your little script there and I get this message in the title area of the browser
---> <br/> <b>Parse error</b>: parse error, expecting '," or ';" in<b> c:\phpdev\datawiz\--- it is cut off here . this is what I did for code for the title page

<?php
$page = $_GET['p']; // Declaring the page Variable
switch ($page) { // Starting our switch command
case "default" : // If page = home
echo "Welcome Home";
break; // Allow for next condition
case "about_me" : // if page = pictures
echo "Enjoy my pictures";
break;
default : // If page is not one of the ones set in here
echo "error!"
}
?>

the "default" and "about_me" are my web pages that are in the include dir.
and this i have this in my title section
<title><?php include('includes/title.php'); ?></title>
I also tried changing up the " to just ' but it made no difference
any ideas ? :confused:

Instinct
07-07-2005, 06:15 AM
Hey there datawizard, one simple but often and annoying mistake... :p

after the echo "error!" there is no semi-colon, just add a ; in there like this :
echo "error!" ;

works now on my test server so happy coding.


(for easier linking change ure "default" to "home")

datawizard
07-07-2005, 06:40 PM
Thanks Instinct, that would help having the simi colon there, and I think I need to get my glasses checked cause I went thru the several lines there looking for that, Now I need to figure out how to get the Error off of it when the page first opens up in browser, the page titles display fine when u click on link , but when home page is first displayed it shows error instead of welcome home

datawizard
09-07-2005, 06:14 PM
Well one easy cheat to fix that "error" is to replace Error with the home message, but Im curious as to know why when page loads ( page is set up using the Templating System with home page loading as default or main page if you will,
Also , Im wondering if this same code can be used in the main page to change up the window status ( area on bottom of web browser that displays http:www.yoursite.page ) I tried coding it like this to see if it would work but I get a parsing error

<?php
$window.status = $_GET['p']; // Declaring the page Variable
switch ($window.status) { // Starting our switch command
case "home" : // If page = home
echo "Welcome Home";
break; // Allow for next condition
case "about_me" : // if page = pictures
echo "Enjoy my pictures";
break;
default : // If page is not one of the ones set in here
echo "error!";
}
?>

On my old home page ( www.datawizard2004.com ) I have the window.status coded in with the onmouse over with a standard link, for some reason when I do the onmose click on the template system , it doent work, Im not sure if its cause of the A Href being "href="index.php?p=home" , any ideas on this ? :D

Instinct
11-07-2005, 02:48 PM
datawizard, i believe the onmouseover affect u are on about is in javascript and not php.... the code you provided above is simply checkin if the set variable (which is equal to 'p' , ie index.php?p=x)

there is no javascript action in the code you provided and so that may be where the fault is.

btw wat line was the parsing error on?

datawizard
11-07-2005, 06:55 PM
There was no parsing error , it was ther "error " message that was shown in this condition "If page is not one of the ones set in here". that always showed up when home page is first acessed, , the proper home message"welcome home, shows up when u hit the home link, what I ment on "cheat was to copy the home message and replace the "error" message there, I was just wondering why it wasnt finding the home page when its first loaded, maybe an extra line of code telling it to load such and such page first and to display proper message.

2nd part, yes the window.status is a javascript that I have coded into the onclick
I was wondering if same script that is used for the title can be used for displaying window status ,that way there is no extra coding added to the onclick command. I hope this makes sense, my heads kinda foggy today :o

Instinct
12-07-2005, 07:05 AM
well for topic 1 : the default : part of our switch tells the browser wat to do if no other 'case' is met.

and as for topic 2, i'd have to see the copy of the javascript ure using.

datawizard
12-07-2005, 02:05 PM
right in topic 1 , the error is when is the other case isnt met, problem is the other case is met , cause "home" is loaded when page first opens up in the browser and when the home button is clicked on the page doesnt reload but the proper saying shows up.

case 2 its simple javascript there , command is onmouseover="window.status='welcome home'; return true" , what I was wanting to do was to do the same thing as what was done for the title except it would be for the window status portion of browser

Instinct
12-07-2005, 03:52 PM
OK i figured it out! your variable is declared below the title... therefore not showing up as home but as "" (blank)....

right at the top of your page put the if clause...

<? if (!isset($_GET[p])) { $page = "Home"; } ?>

this shuld declare your page variable which will be switched for in the title.



i dont get how you plan to use this in the second problem....

u have :

Home
Pictures
Dinosaurs (for ex sake)
About

and u want the mouse to display the SAME thing for each of them ?? or individual ones depending what the link is called?

i've just built a category based cms system using mysql backbone, which has a developed navigation system, it is simple to do but will need you to have a second 'module' to control the navigation menu.

datawizard
13-07-2005, 10:14 PM
Hi there, small Q here, which page do I need to insert <? if (!isset($_GET[p])) { $page = "Home"; } ?> into , the title page or the main index page ?

and as far as the 2nd prob , dont worry about it, im just gonna use the onmouse java command, :)

Instinct
14-07-2005, 06:33 AM
put that in the top of the index file...

right at the top... you could also keep your code cleaner by changing it to :

<? if (!isset($_GET[p])) { $page = "Home"; } else { $page = $_GET[p]; } ?>

this will just make sure that for the whole document and any included documents, unless the $page variable is re-set, it will equal home when no index.php?p= is seleceted or equal the value set for p in the web address.

- Hector

datawizard
14-07-2005, 07:56 AM
Humm , that didnt do the trick as i still get the "error" message , I put that string rite at the top of the index.php page , i checked both scripts and am pasting them in here
here is script that is in the index.php to load the "home" page

<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/home.php");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".php");
}?>

This portion is what i have at the top of my index.php page
<? if (!isset($_GET[p])) { $page = "Home"; } else { $page = $_GET[p]; } ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title><?php include('includes/title.php'); ?></title>

and finally and this is portion of what i have in my "title" page
<?php
$page = $_GET['p']; // Declaring the page Variable
switch ($page) { // Starting our switch command
case "home" : // If page = home
echo "Datawizard main page";
break;

Instinct
15-07-2005, 09:49 AM
after lookin carefully and helping other out at other forums were i support,

i realised u put ="Home" where your swich is asking for "home" ;)

either a) change ="Home" to ="home"
or b) put case "Home" : directly above case "home" :
both should work it just different methods

datawizard
15-07-2005, 05:33 PM
I didnt know PHP was case senitive but that still didnt fix it , it still shows "error"
Im startin to go bald here lolol, casue the line makes perfect sense but why aint it pickin up the page??? :confused:
PS what other forum do u support in, I'd like to read up on some of your help, it may answer some of my questions that I havent though up yet, hehehe

Instinct
20-07-2005, 02:16 PM
well if you would like to send me a copy of your source code i'd like to go through it.... pm me for my email address.

and as for my other support on forums, i've recently moved to a new community, however i am dedicated to this forum and wouldnt like to send away Jame's viewers, i have no reason to point anyone away from this forum as we have always managed to find a solution to every single problem braught here, so far :)

if James doesnt mind i will give you the link but until then, i'm an InfernoForum helps-man :p

AW/ME
19-05-2006, 03:30 PM
Hi James,

Very new to php, started yesterday! Loved this tutorail... but can you help?

<html>
<head>
<title>InfernoForums Template System Tutorial - Version 1</title>
<link href="test.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td colspan="2"><a href="http://infernoforums.com/index.php?showtopic=143%20">InfernoForums Template System Tutorial
</a> <hr></td>
</tr>
<tr>
<td width="150"><ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?p=handout2">About Us</a></li>
<li><a href="index.php?p=handout3">Contact Us </a></li>
</ul></td>
<td align="left" valign="top">
<?php
if (!isset($_GET['p'])) { // no page specified -> load content from default.txt
include("includes/handout1.txt");
} else { // page specified -> load content from relevant text file
include("includes/" . $_GET['p'] . ".txt");
?>
</td>
</tr>
<tr align="center">
<td colspan="2">
<hr>

Footer Here <br>Copyright 2004 YourCompany.com </td>
</tr>
</table>
</body>
</html>

What Im trying to do is; click a button say 'about us' and not only the wording change but a picture change depending on the page aswell. I managed to make the text change or a picture change but not both at the same time. And how can you change text else where on the page?

IH-James
21-05-2006, 08:31 AM
Hi everyone,

I have updated the code for index.php. Some checking is now done on the p variable, to ensure it is valid. This is done to increase security of the script.

I highly recommend that everyone updates their code.

IH-James
21-05-2006, 08:38 AM
What Im trying to do is; click a button say 'about us' and not only the wording change but a picture change depending on the page aswell. I managed to make the text change or a picture change but not both at the same time. And how can you change text else where on the page?As for displaying different images, you could do something like:
// show an image depending on what page we are on:
switch ($_GET['p']) {
case "about": ?>
<img src="images/about.jpg">
<?php
break;

case "contact": ?>
<img src="images/contact.jpg">
<?php
break;
case "anotherPage": ?>
<img src="images/another_pic.jpg">
<?php
break;

default:
// we are probably on the default page
?>
<img src="images/home.jpg">
<?php
}
A switch statement is effectively the same as an if ... else if ... else if ... else if ... else ... combination.

You could do something similar for bits of text too.

Cheers,

AW/ME
22-05-2006, 01:48 PM
Thanks alot, I can work out whats going on there fine... But for some reason when I upload, its saying there is a fault on line 67?? the </html> line...hey|!! any ideas?

// show an image depending on what page we are one:
switch ($_GET['p']) {
case "about": ?>
<img src="imgages/handout3.jpg">
<?php
break;

case "contact": ?>
<img src="imgages/handout3.jpg">
<?php
break;
default:
//we are probably on the default page
?>
<img src="images/handout1.jpg">
<?php
break;
}
?>
</td>
</tr>
<tr align="center">
<td colspan="2"><hr>
Footer Here <br>Copyright 2004 YourCompany.com </td>
</tr>
</table>
</body>
</html>

Thanks for the help, this tutorail has been a reall inspiration,,,,, Has version 2 come out yet???

AW/ME
22-05-2006, 01:57 PM
// show an image depending on what page we are one:
switch ($_GET['p']) {
case "about": ?><img src="images/handout3.jpg"><?php break;
case "contact": ?><img src="images/handout3.jpg"><?php break;
default: ?><img src="images/handout1.jpg"><?php break;
} ?>
</td>
</tr>
<tr align="center">
<td colspan="2"><hr>
Footer Here <br>Copyright 2004 YourCompany.com </td>
</tr>
</table>
</body>
</html>

IT WORKS.... What a beauty! YES. Thanks every so much!!

IH-James
23-05-2006, 08:05 AM
That's good to hear.

I assume you were missing a PHP closing tag?>?

AW/ME
31-05-2006, 09:30 AM
That was it.

Thanks for the help... really appreciated.

carlsen
14-06-2006, 04:15 PM
Greetings and thx for a very usefull guide.

However - I cant figure out how to make the chosen menu-select highligted. Read this guide http://www.alistapart.com/articles/keepingcurrent/# , but I cant get it working.

I guess there is a simple way to make it happend ...

And an ekstra question: I often see this array in stead of yours:

$validpage = array (
'index' => 'Home',
'contact' => 'Contact us',
'loen_og_regnskab' => 'another thing',
);

What is the difference?

thx

carlsen

IH-James
15-06-2006, 02:37 AM
However - I cant figure out how to make the chosen menu-select highligted.
Hi Carlsen,

You could do something like this:

<ul>
<li><?php if (isset($_GET['p'])) echo '<a href="index.php">Home</a>'; else echo 'Home'; ?></li>
<li><?php if (isset($_GET['p']) && $_GET['p'] != 'about') echo '<a href="index.php?p=about">About Us</a>'; else echo 'About Us'; ?></li>
<li><?php if (isset($_GET['p']) && $_GET['p'] != 'contact') echo '<a href="index.php?p=contact">Contact Us</a>'; else echo 'Contact Us'; ?></li>
</ul>
Using that code means that the menu option is printed without a link if it is the current page.

Does this make sense?

Cheers,

carlsen
15-06-2006, 09:04 AM
Thx - it seems to work. However ... I need to control it by my stylesheet.

Right now it looks like this:

$validPages = array(
'index',
'jura',
'politik');

The navigation goes like this:

<li <?php if ($thisPage=="jurabummelum") echo " id=\"currentpage\""; ?>><a
href="index.pgp?p=jura>Juridisk bistand</a></li>
<li <?php if ($thisPage=="polle fra snave") echo " id=\"currentpage\"";
?>><a href="index.pgp?p=politik>Juridisk bistand</a></li>

Ant the page jura.txt contains <?php $thisPage="jurabummelum"; ?>

It all works with some #navigation #currentpage {color: red}

Anyway - that solution gives me some hard manual work. Is there a way to name the page (and give it a title)?

Like

$validPages = array(
'index', => 'Home',
'jura', => 'jurabummelum',
'politik' => 'Politics and so on');

and then use the 'jurabummelum' somehow in <title> ...-... </title> and in the jura.txt file in <h1>...-...</h1>

Ant then ofcource in this line:

<li <?php if ($thisPage=="jurabummelum") echo " id=\"currentpage\""; ?>><a
href="index.pgp?p=jura>Juridisk bistand</a></li>

Or is this more the way:

$validPages = array(
'index' => array(
'title' => 'Indeks',
'file' => 'index.txt',
'menutext' => 'Forside'
),
'jura' => array(
'title' => 'Side om juridisk bistand',
'file' => 'jura.txt',
'menutext' => 'Juridisk bistand'
),
'politik' => array('title' => 'Side om politik', ...)
);

thx

rasmus

xjosie729
09-09-2006, 06:01 PM
This is great! Just what I'm looking for.

But is there anyway to display a 404 not found error message instead of the default page when a page is not found?

IH-James
10-09-2006, 02:42 PM
This is great! Just what I'm looking for.

But is there anyway to display a 404 not found error message instead of the default page when a page is not found?Hi,

you could do something like:

if (isset($_GET['p']) && in_array($_GET['p'], $validPages)) {
if (file_exists("includes/" . $_GET['p'] . ".txt")) {
// a page has been specified and is a valid option, and the required file exists
// load content from relevant text file
include("includes/" . $_GET['p'] . ".txt");
} else {
// file doesn't exist
header("HTTP/1.1 404 Not Found");
}
} else {
// no page specified -> load content from default.txt
include("includes/default.txt");
}

I hope this helps.

xjosie729
10-09-2006, 04:34 PM
I get the error: Parse error: parse error, unexpected '}' when I do that.

IH-James
11-09-2006, 06:57 AM
I get the error: Parse error: parse error, unexpected '}' when I do that.That segment of code I pasted should work.

Can you paste the contents of the whole PHP file?