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! |
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |