I developed an easy way to create a templated web site using a template and text files. Then to modify those text files, I developed a simple editor and updater. It is very simple and the user only needs to know HTML. There is no need for a database. This batch of code is for 4 pages. Read teh comments for directions. Check it out....
By : zensmile
/* First off, design your template page in your text editor or WYSIWYG editor of choice. Where you want the "content" to show up within the page, include this code: */
/************************ Begin Code ************************/
<?php
$thefile = "data/$page.txt";
if (file_exists($thefile))
{
include("$thefile");
}
else
{
include("data/error.txt");
}
?>
/************************ End Code ************************/
/*All of your links should look like this:
template.php?page=whatever
Where the link reads "whatever", replace with a file name without the .txt extension. For example, template.php?page=faq, would include "faq.txt" within your template page.
Create a "data" directory and put all of your content files within that directory. The .txt files will contain all of the "meat an potatoes" of your site...formatted in HTML *without* the <HTML><HEAD> or <BODY> tags. All of those tags are within your template.php. For example, you might have a contact page, a faq page, and a downloads page. You would have a faq.txt, contact.txt, and a downloads,txt within your data directory. So your links would look like this:
template.php?page=faq
template.php?page=contacts
template.php?page=downloads
*/
/* this next batch of code should be in a file called update.php within your "data" directory. You use this page to edit your .txt files within "data". You would access it by typing in...
http://www.whatever.com/data/update.php
You will then be asked for a login and password. Here is the script for update.php: */
/************************ Begin Code ************************/
<?php
//Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
//If empty send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization required.';
exit;
}
//If not empty, do something else
else {
//Try to validate the values of $PHP_AUTH_USER and
//$PHP_AUTH_PW against hard-coded values
//please change login and password to whatever you want
if (($PHP_AUTH_USER == "login") && ($PHP_AUTH_PW == "password")) {
echo "
<html lang=\"en\">
<head>
<title>Enter Your Title Here</title>
</head>
<body>
<h3>Header</h3>
<p>Please be very careful when editing these files. Be particularly careful when editing the PHP files.
<p>Choose a page to edit and then hit the submit button.
<p>
<form action=\"modify.php\" method=\"post\">
<table width=\"500\" border=\"1\" cellspacing=\"1\" cellpadding=\"5\">\n
<tr bgcolor=\"#CCCCCC\"><th>Pick</th><th>File Name</th><th>Last Edited or Uploaded</th></tr>\n
";
$handle=opendir('.');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != ".."
&& $file != "update.php" && $file != "write.php" && $file != "modify.php") {
$filename = str_replace("_"," ",$file);
$fTime = filemtime($file);
$today = getdate($fTime);
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
echo "<tr><td align=\"center\"><input type=\"radio\" value=\"$filename\" name=\"working\"></td><td align=\"center\"><b>$filename</b></td><td align=\"center\">$month $mday,
$year</td></tr>\n
";
}
}
closedir($handle);
echo "</table>\n";
echo "<p><input type=\"submit\" value=\"Submit\">";
echo "</form>";
echo " </body>
</html>";
}
else {
echo "You are not authorized!";
}
}
?>
/************************ End Code ************************/
/* Here is the code for "modify.php", which is also located in the "data" directory. Modify.php is the "action" for the upate.php file. You choose a file to modify and then the information is passed to modify.php. Here is the code: */
/************************ Begin Code ************************/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
<title>Your Title Here</title>
</head>
<body>
<h3>Modify Data Document</h3>
<p>Carefully read the text below, edit, and then submit to publish to web site. All changes are final! Please make sure that you have spell checked document and all "curley quotes and apostrophes" have been eliminated.
<p>You must also use HTML markup in the document. Please, read an HTML manual before getting "freaky" with the editing.
<form method="post" action="write.php">
<textarea name="message" rows="20" cols="60">
<?php
$contents=file($working);
for ($i=0; $i<sizeof($contents);$i++){
echo htmlentities($contents[$i]);
}
echo "</textarea>\n";
echo "<input type=\"hidden\" value=\"$working\" name=\"working\">";
?>
<p>
<input type="submit">
</form>
</body>
</html>
/************************ End Code ************************/
/* Here is the code for "write.php". It is, again, located within the "data" directory. Write.php is the action for "modify.php". After you have made your changes to the .txt file, the changes are written and then you are redirected to the update.php page. Here is the code: */
/************************ Begin Code ************************/
<?php
$writeme=fopen("$working","w");
fputs($writeme, stripslashes($message));
fclose($writeme);
header("Location: http://www.yourdomain.com/data/update.php\n\n");
?>
/************************ End Code ************************/
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Content Management Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |