|
|
|
GuestBook Light
Description: This package is a plug and play application for any website. It does not require any database connectivity. All the entries are saved in a text file. The filename starts with .ht which is protected by Apache server. For further addition to the file, it is advisable to save it below the web root.
Author : Ehsan Haque
Web : http://ehsan.bdwebwork.com
Created : 4th June 2006
Demo : http://resource.bdwebwork.com/GuestBookLight/
guestBook.php
| <?php
/*
* GuestBook Light
* ====================================================================
* Description: This package is a plug and play for any website. It
* does not require any database connectivity. All the entries are
* saved in a text file. The filename starts with .ht which is
* protected by Apache server. For further addition to the file, it is
* advisable to save it below the web root.
* ====================================================================
* Author : Ehsan Haque
* Web : http://ehsan.bdwebwork.com
* Created : 4th June 2006
* Demo : http://resource.bdwebwork.com/GuestBookLite/
*
* Filename : guestBook.php
* Purpose : Displays Guest Book entries and a form for users to sign
*/
require_once("functions.php");
/*
* Comment is added in this Block
*/
if ((!empty($_POST['cmd'])) && ($_POST['cmd'] == "add"))
{
// Save comment
$addComment = addComment();
if (!$addComment)
{
// Message to show when save process fails
$msg = "Could not add your comment.\nPlease make sure you entered required fileds and try again.";
if (!empty($_POST))
{
// If save process fails the values for each input fields are set here
foreach ($_POST as $key => $value)
{
$$key = stripslashes(strip_tags(trim($value)));
}
}
}
else
{
$successMsg = "Thank you for Signing my Guest Book";
}
}
/*
* Get Guest Book Entries
*/
$gBEntries = getGBEntries();
?>
<html>
<head>
<title>Guest Book</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
</head>
<body bgcolor="">
<table width="100%" cellpadding="0" cellpadding="0" style="border: 0px">
<tr>
<td rowspan="2" valign="top">
<?php
if (!empty($successMsg))
{
echo "<span class='success'>" . $successMsg . "</span><br><br>";
}
if (!empty($gBEntries))
{
$k = 0;
$j = 0;
if (!empty($_GET['start']))
{
/*
* Used for Pagination Purpose
* -- Value corresponds to the starting index number
*/
$k = $_GET['start'];
}
// Iterate through the entries and print
for ($i = 0+$k; $i < PAGE_LIMIT+$k; $i++)
{
$webAdd = "";
if (!empty($gBEntries[$i]))
{
echo "<b>Name:</b> " . stripslashes($gBEntries[$i]['Name']);
if (!empty($gBEntries[$i]['Web']))
{
$webAdd = str_replace("http://", "", $gBEntries[$i]['Web']);
echo "<br>";
echo "<b>Web:</b> <a href='http://$webAdd' target='_blank'>" . stripslashes($gBEntries[$i]['Web']) . "</a>";
}
echo "<br>";
echo "<b>Signed on: </b> " . $gBEntries[$i]['Time'];
echo "<br>";
echo "<b>Comments:</b><br>";
echo nl2br(stripslashes($gBEntries[$i]['Comment']));
echo "<br><hr>";
}
}
$j = ($i - PAGE_LIMIT)-PAGE_LIMIT;
}
// Setting the PREVIOUS link
if ((count($gBEntries) > PAGE_LIMIT) && ($j >= 0))
{
echo "<a href='?start=$j'>PREVIOUS</a>";
}
// Setting the NEXT link
if ((count($gBEntries) > PAGE_LIMIT) && ($i < count($gBEntries)))
{
echo " <a href='?start=$i'>NEXT</a>";
}
?>
</td>
<td width="40%" valign="top">
<table width="100%" cellpadding="5" cellspacing="0" align="right">
<tr>
<td style="font-size:18px" colspan="2">Sign my Guest Book</td>
</tr>
<tr>
<td class="note" colspan="2" style="border-bottom:1px solid #AEB6C2">* Fields are required</td>
</tr>
<?php
if (!empty($msg))
{
echo "<tr><td colspan='2' align='center' class='note' style='border-bottom:1px solid #AEB6C2'>" . nl2br($msg) . "</td></tr>";
}
?>
<form action="" method="POST">
<tr>
<td width="30%">Name *</td>
<td align="right"><input type="text" name="yourname" value="<?php echo (!empty($yourname)) ? $yourname : null;?>" size="35"></td>
</tr>
<tr>
<td width="30%">Email</td>
<td align="right"><input type="text" name="youremail" value="<?php echo (!empty($youremail)) ? $youremail : null;?>" size="35"></td>
</tr>
<tr>
<td width="30%">Web</td>
<td align="right"><input type="text" name="yourweb" value="<?php echo (!empty($yourweb)) ? $yourweb : null;?>" size="35"></td>
</tr>
<tr>
<td colspan="2">Comment *</td>
</tr>
<tr>
<td colspan="2" align="center"><textarea name="yourcomment" rows="10" cols="55"><?php echo (!empty($yourcomment)) ? $yourcomment : null;?></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="add" value="Sign Guest Book">
<input type="reset" name="cancel" value="Clear My Text">
</td>
</tr>
<input type="hidden" name="cmd" value="add">
</form>
</table>
</td>
</tr>
</table>
</body>
</html> | |
functions.php
| <?php
/*
* Filename : functions.php
* Purpose : Contains functions to add comments, return list of comments
*/
session_start();
/*
* Defining Constants
* -- GB_FILENAME : The filename that contains the Guest Book entries. This file is named
* starting with .ht, which by default in Apache Configuration is protected.
* To ensure further protection it is advisable to keep the file outside
* web root directory.
* -- PAGE_LIMIT : Number of Entries to show per page
*/
define('GB_FILENAME', ".htguestbook");
define('PAGE_LIMIT', 5);
$gBFilename = GB_FILENAME;
// Creating the file if file does note exists and placing the pointer at the end of the file
$gBFile = fopen($gBFilename, "a+");
fclose($gBFile);
/*
* This function adds comment to the above mentioned protected text file
* return boolean
*/
function addComment()
{
/*
* Checking if $_POST is empty or not. If not, it creates variables with the named
* of input fields passed from Guest Book form and assigns the respective values to them.
*/
if (!empty($_POST))
{
foreach ($_POST as $key => $value)
{
// Taking out all the HTML tags and trimming the values
$$key = strip_tags(trim($value));
}
}
// Guest's name cannot be left blank, so returns false if found blank
if ($yourname == "")
{
return false;
}
// Guest's comment cannot be left blank, so returns false if found blank
if ($yourcomment == "")
{
return false;
}
/*
* Create a MD5 of entry made
* -- This will be used to make sure refreshing a page does not add duplicate entries
*/
$entryMD5 = MD5($yourname . $youremail . $yourweb . $yourcomment);
if ((!empty($_SESSION['entryMD5'])) && ($_SESSION['entryMD5'] == $entryMD5))
{
return true;
}
$gBFilename = GB_FILENAME;
$gBFile = fopen($gBFilename, "a+");
$datetime = date("Y-m-d H:i:s T");
/*
* Preparing the Guest Book entry
* -- Every entry is seperated by ==
* -- Every field is seperated by ||||
* -- Every key and value of a field is seperated by ^^^^
*/
$gBEntry = "==";
$gBEntry .= "Name^^^^$yourname||||";
$gBEntry .= "Email^^^^$youremail||||";
$gBEntry .= "Web^^^^$yourweb||||";
$gBEntry .= "Time^^^^$datetime||||";
$gBEntry .= "Comment^^^^";
$gBEntry .= $yourcomment;
// Writes the entry to protected text file
$signGB = fwrite($gBFile, $gBEntry);
// MD5 of entry is saved in session
$_SESSION['entryMD5'] = $entryMD5;
fclose($gBFile);
return true;
}
/*
* This function fetches the Entries from the protected text file
* and creates an array to return. By default array_reverse() is used
* to sort the list in Descending order.
* return array
*/
function getGBEntries()
{
$list = array();
$item = array();
$gBFilename = GB_FILENAME;
$gBFile = fopen($gBFilename, "a+");
// Reads the file if the filesize is greater than 0
if (filesize($gBFilename) > 0)
{
// Assigns the content to a variable
$gBFileContent = fread($gBFile, filesize($gBFilename));
fclose($gBFile);
}
if (!empty($gBFileContent))
{
// Seperating the entries
$entriesArr = explode("==", trim($gBFileContent));
if (!empty($entriesArr))
{
foreach ($entriesArr as $key => $value)
{
if ($value != "")
{
// Seperating fields
$lineArr = explode("||||", $value);
foreach ($lineArr as $lineKey => $lineValue)
{
// Seperating key and value of each field
$itemArr = explode("^^^^", $lineValue);
$item[$itemArr[0]] = $itemArr[1];
}
/*
* Creating the array of entries
* -- $list[index] = $item[fieldKey] = fieldValue
* -- e.g. $list[2] = $item['Name'] = 'Ehsan Haque'
*/
$list[] = $item;
}
}
// Reversing the array to sort entry in Descending order
$list = array_reverse($list);
}
}
return $list;
}
/*
* This function dumps a variable
*/
function dump($var)
{
echo "<pre>";
print_r($var);
echo "</pre>";
}
?> | | |
|
| File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection. Categories : Complete Programs, Content Management, Filesystem, PHP | | | Finds files on your site, uses UNIX find command. Categories : Complete Programs, Filesystem, PHP | | | AITSH Statistics Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP | | | This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics, Filesystem, PHP, Complete Programs | | | Disk Usage, uses UNIX du command. Categories : Complete Programs, PHP, Filesystem | | | QTO File Manager Categories : Filesystem, filePro, Complete Programs, PHP, Content Management | | | Contents Page - a script to build contents pages. Categories : Complete Programs, PHP, Utilities, Filesystem | | | Handle multiple file upload Categories : Complete Programs, Filesystem, PHP, HTML and PHP | | | Directory viewer, customize how you display the file structure, easy to
understand. Found out about PHP 3 days ago, and this is my first prog. Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP | | | Complete NotePad application for Websites (Like Yahoo Notepad) Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Searches through a local INN server's discussions Categories : Search, Complete Programs, PHP | |
|
|
|