Old 04-25-2005   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Tech Support
 
Man1c M0g's Avatar
 
Tournaments Won: 1

Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,202
Blog Entries: 21
Images: 3

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Simple Template Systems

This is a thread to discuss the Simple Template Systems tutorial. Please keep all posts on-topic, don't spam, and read the entire thread BEFORE you post - any issues you have could be answered deeper within the thread.
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-19-2005   #2 (permalink)
stingerblue
Guest
 

Posts: n/a

Post

good tutorial, good sercurity (doesnt allow exploiting /index.php?p=www.exploit.com/attack.php type stuff)
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-24-2005   #3 (permalink)
Registered User
 
ViciOuS's Avatar
 

Join Date: Apr 2005
Posts: 82

PHP Code:
<?php
$page 
$_GET['p'];
if ((
$page == "news") or ($page =="")) { include('news.php');
} else if(
$page == "tutorials") { include('tutorials.php');
} else if(
$page == "downloads") { include('downloads.php');
} else if(
$page == "faqs") { include('faqs.php');
} else if(
$page == "links") { include('links.php');
} else if(
$page == "legalinfo") { include('legalinfo.php');
} else if(
$page == "privacy") { include('privacy.php');
} else { include(
'404error.php');
}
?>
A clump a code like the above isn't all that confusing to the average coder.. But what if you have 20 pages or more.. or maybe you just need a different way to get he same effect.

Well, that's when the Switch construct comes into play. Click the link to read all about the switch construct in the online php manual.

Here is what it would look like if you were to use a switch construct for M0g's tutorial.

PHP Code:
<?php
// Think of each case as an if/else statement.
// The default is what will be shown if no other 
// case matches the variable.
//
// Each 'break' at the end of each case (except the default)
// tells php to stop, and continue after the switch.

$page $_GET['p'];

switch (
$page)
{
    
// if page is equal to nothing, continue to the news case
    
case '':
    case 
'news':
        include(
'news.php');
        break;
    case 
'tutorials':
        include(
'tutorials.php');
        break;
    case 
'downloads':
        include(
'downloads.php');
        break;
    case 
'faqs':
        include(
'faqs.php');
        break;
    case 
'links':
        include(
'links.php');
        break;
    case 
'legalinfo':
        include(
'legalinfo.php');
        break;
    case 
'privacy':
        include(
'privacy.php');
    
// If no other case is matched, 
    // display the default 404 error page.
    
default:
        include(
'404error.php');
}
?>
It may seem like a lot of code, but once you get familiar with the switch construct, it is really simple. Also, if you were to take my comments out, it would be half the code .

You can use this type of code branching for many many different things. Experiment, do some trial and error, study it, and ultimately.. Have Fun!!!

Last edited by ViciOuS; 06-24-2005 at 10:16 PM. Reason: used PHP bbcode instead of CODE bbcode
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-04-2005   #4 (permalink)
stingerblue
Guest
 

Posts: n/a

is there any web sites that have examples around this code that go further?

I have experimented with it, but none have worked (graphics, and title)
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-02-2005   #5 (permalink)
72dpi
Guest
 

Posts: n/a

Taking it one step Further

Great usage of the Switch method,
however, I feel that people should be able to expand further, so we can include as many pages as we want .

Save this document as index.php

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<table width="700"  border="0" cellpadding="5" cellspacing="1" bgcolor="#eaeaea">
  <tr bgcolor="#eaeaea">
    <td height="100" colspan="2">&nbsp;</td>
  </tr>
  <tr align="left" valign="top">
    <td width="175" bgcolor="#f5f5f5"><h4>Navigation</h4>
      <a href="index.php">Home</a><br />
      <a href="index.php?page=contact">Contact</a><br />
      <a href="index.php?page=links">Links</a><br />
      <a href="index.php?page=downloads">Downloads</a><br />
      <br />
      </td>
    <td bgcolor="#ffffff">
    <h2>Welcome to My Site </h2>
    <?php 
$thefile 
"includes/$page.php"
if (
file_exists($thefile)) 

include(
"$thefile"); 

else 

include(
"includes/start_content.php"); 


?></td>
  </tr>
  <tr align="center" bgcolor="#eaeaea">
    <td height="30" colspan="2">&copy; 2005 Yourname</td>
  </tr>
</table>
</body>
</html>
Create a folder called "includes"

Next, save this as start_content.php in that folder:
(note we can stop people opening the page directly (good 4 security)

PHP Code:
<? 
// keep people from accessing this page directly 
if (eregi('start_content.php'$_SERVER['PHP_SELF'])) { 
// go to index page 
    
header('Location: ../index.php?page=start_content'); 
    die(); 


?>
<p>Start Content Goes Here!</p>
Save this as contact.php
(This is a fully functioning contact form I have added to help out).
Just edit the content where appropriate.
PHP Code:
<? 
// keep people from accessing this page directly 
if (eregi('contact.php'$_SERVER['PHP_SELF'])) { 
// go to index page 
    
header('Location: ../main.php?page=contact'); 
    die(); 


?>
<h4>ContactPage</h4>
Blah Blah
I hope this helps someone else out there. Just add more pages, using the headers as shown to prevent people opening the pages without going via the link "index.php?page=whatever"
Now you can see we can add more pages so easily, sinmce we are not stuck to predefined content blocks..!

Last edited by Man1c M0g; 12-26-2006 at 09:58 AM.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-13-2006   #6 (permalink)
Registered User
 
psychophat's Avatar
 

Join Date: Dec 2005
Posts: 5

Send a message via ICQ to psychophat Send a message via MSN to psychophat
Thumbs up

72dpi in using your posted script do I need to add links like the previous script of ViciOuS in this topic or do I just add the headers on every page I make? If so how does it detect if the page is invalid and would redirect to the custom error404.php page?

I'm new to PHP so could anyone explain the further usages of the script above.
__________________
Wake up . . . time to die !!!

Last edited by psychophat; 01-13-2006 at 07:18 AM.
psychophat is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-14-2006   #7 (permalink)
Registered User
 

Join Date: Jan 2006
Posts: 1

I was trying to follow 72dpi post but got lost with trying to understand where $page.php was defined. Can someone show me what I missed or was it not defined?

Got it

Last edited by nassaublu; 05-05-2007 at 04:08 PM.
nassaublu is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-29-2007   #8 (permalink)
Registered User
 
mytruedesire's Avatar
 

Join Date: Nov 2007
Location: oregon
Posts: 8
Images: 5

Send a message via MSN to mytruedesire
Thumbs up thanks

that makes sense now lol.i couldnt really figure that out when i read other peoples tutorials for it.i use wordpress so i dont have to do much coding.i would like to know how to skin wordpress though.
mytruedesire is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://forums.biorust.com/tutorial-commenting-system/1677-simple-template-systems.html
Posted By For Type Date
BioRUST.com :: Tutorials >> Simple Template Systems This thread Refback 11-19-2007 10:27 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
CIS (Continuous ink systems) Tony_photoplus General Discussions 9 04-29-2007 03:50 PM
Web template Vlad_einhorn Adobe Photoshop 3 11-19-2005 10:08 PM
Booking systems? Joe HTML / PHP / ASP / JS 14 09-07-2004 04:23 PM
Resurrection of the old game systems colfit2 General Discussions 6 04-06-2004 04:16 AM
Open Source Operating Systems Order General Discussions 20 11-24-2003 09:54 AM


All times are GMT +1. The time now is 07:34 PM.

Powered by vBulletin Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT