WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions Click here to Update Your Picture
Ehsan Haque
Date : Jun 04th 2006
Grade : 4 of 5 (graded 3 times)
Viewed : 13282
File : 4414.zip
Images : No Images for this code example.
Search : More code by Ehsan Haque
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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>"
  }
 
?>



Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
Disk Usage, uses UNIX du command.
Categories : Complete Programs, PHP, Filesystem
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
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
QTO File Manager
Categories : Filesystem, filePro, Complete Programs, PHP, Content Management
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
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
Contents Page - a script to build contents pages.
Categories : Complete Programs, PHP, Utilities, Filesystem
php Free chat simple fast and customizable chat server that uses a simple filesystem for message and nickname storage
Categories : PHP, AJAX, XML, Complete Programs
Form Security - Match A Value For Success
Categories : PHP, Authentication, HTML and PHP, Sessions, Security
simple shopping cart for php3
Categories : PHP, PHP Classes, Complete Programs, Ecommerce
Modification of Shane Caraveo's guestbook. Uses ODBC...some code modifications
Categories : ODBC, Databases, Complete Programs, PHP
An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files