Writing a guestbook script. Create a guestbook Crazy guestbook html

In this tutorial, we will create a guestbook in PHP using AJAX. The records will be stored in the database. The table will contain the following information: sender's name, email address, IP address and date-time of the last entry. jQuery will be used (to implement AJAX). A simple spam protection will also be implemented - you can post no more than one entry every 10 minutes.

Step 1: SQL

For our application to work, we need to create a table:

CREATE TABLE IF NOT EXISTS `s178_guestbook` (`id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) default "", `email` varchar(255) default "", `description` varchar(255) default "", `when` int(11) NOT NULL default "0", `ip` varchar(20) default NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Step 2 PHP

The main file will contain the following code:

guestbook.php

=") == 1) error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); else error_reporting(E_ALL & ~E_NOTICE); require_once("classes/CMySQL.php"); // including service class to work with database // Get Visitor IP function getVisitorIP() ( $ip = "0.0.0.0"; if((isset($_SERVER["HTTP_X_FORWARDED_FOR"])) && (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))) ( $ip = $ _SERVER["HTTP_X_FORWARDED_FOR"]; ) elseif((isset($_SERVER["HTTP_CLIENT_IP"])) && (!empty($_SERVER["HTTP_CLIENT_IP"]))) ( $ip = explode(".",$_SERVER[ "HTTP_CLIENT_IP"]); $ip = $ip.".".$ip.".".$ip.".".$ip; ) elseif((!isset($_SERVER["HTTP_X_FORWARDED_FOR"])) | | (empty($_SERVER["HTTP_X_FORWARDED_FOR"]))) ( if ((!isset($_SERVER["HTTP_CLIENT_IP"])) && (empty($_SERVER["HTTP_CLIENT_IP"]))) ( $ip = $_SERVER ["REMOTE_ADDR"]; ) ) return $ip; ) // Get the latest entries in the guestbook function getLastRecords($iLimit = 3) ( $sRecords = ""; $aRecords = $GLOBALS["MySQL"]->getAll( "SELECT * FROM `s178_guestbook` ORDER BY `id` DESC L IMIT($iLimit)"); foreach ($aRecords as $i => $aInfo) ( $sWhen = date("F j, Y H:i", $aInfo["when"]); $sRecords .=<<

($aInfo["description"])

EOF; ) return $sRecords; ) if ($_POST) ( // Accept new records $sIp = getVisitorIP(); $sName = $GLOBALS["MySQL"]->escape(strip_tags($_POST["name"])); $sEmail = $GLOBALS ["MySQL"]->escape(strip_tags($_POST["name"])); $sDesc = $GLOBALS["MySQL"]->escape(strip_tags($_POST["text"])); if ($ sName && $sEmail && $sDesc && $sIp) ( // Anti-spam $iOldId = $GLOBALS["MySQL"]->getOne("SELECT `id` FROM `s178_guestbook` WHERE `ip` = "($sIp) " AND `when` >= UNIX_TIMESTAMP() - 600 LIMIT 1"); if (! $iOldId) ( // You can add comments $GLOBALS["MySQL"]->res("INSERT INTO `s178_guestbook` SET `name` = "($sName)", `email` = "($sEmail)", `description` = "($sDesc)", `when` = UNIX_TIMESTAMP(), `ip` = "($sIp)"") ; // Print the last 10 records $sOut = getLastRecords(); echo $sOut; exit; ) ) echo 1; exit; ) // Print the last 10 records $sRecords = getLastRecords(); ob_start(); ?>

Guest book

Add your review here

Guestbook in PHP

When you open the page, you will see a notebook. On the left side, the last three entries are displayed, and on the right, a form for posting a new review. When the form is submitted, the script sends the POST data (to the same PHP page), then stores the received data in the database and returns the last three records. Using the fade effect, entries are displayed on the left side of the book.

Also using PHP file

classes/CMySQL.php

This file contains the class code for working with the database. It requires you to set up three variables to connect to the server.

$this->sDbName = "DATABASE_NAME"; $this->sDbUser = "USER NAME"; $this->sDbPass = "PASSWORD";

Step 3CSS

And now we will form the appearance of the guest book:

css/main.css

*( margin:0; padding:0; ) body ( background-color:#fff; color:#fff; font:14px/1.3 Arial,sans-serif; ) footer ( background-color:#212121; bottom:0; box-shadow: 0 -1px 2px #111111; display:block; height:70px; left:0; position:fixed; width:100%; z-index:100; ) footer h2( font-size:22px; font- weight:normal; left:50%; margin-left:-400px; padding:22px 0; position:absolute; width:540px; ) footer a.stuts,a.stuts:visited( border:none; text-decoration:none ; color:#fcfcfc; font-size:14px; left:50%; line-height:31px; margin:23px 0 0 110px; position:absolute; top:0; ) footer .stuts span ( font-size:22px; font-weight:bold; margin-left:5px; ) .container ( background: transparent url(../images/book_open.jpg) no-repeat top center ; color: #000000; height: 600px; margin: 20px auto; overflow: hidden; padding: 35px 100px; position: relative; width: 600px; ) #col1, #col2 ( float: left; margin: 0 10px; overflow: hidden; text-align: center; width: 280px; ) #col1

( -webkit-transform: rotate(3deg); -moz-transform: rotate(3deg); -ms-transform: rotate(3deg); -o-transform: rotate(3deg); ) #records form ( margin:10px 0; padding:10px; text-align:left; ) #records table td.label ( color: #000; font-size: 13px; padding-right: 3px; text-align: right ; ) #records table label ( font-size: 12px; vertical-align: middle; ) #records table td.field input, #records table td.field textarea ( background-color: rgba(255, 255, 255, 0.4) ; border: 0px solid #96A6C5; font-family: Verdana,Arial,sans-serif; font-size: 13px; margin-top: 2px; padding: 6px; width: 190px; ) #records table td.field input ( background -color: rgba(200, 200, 200, 0.4); cursor: pointer; float:right; width: 100px; ) #records table td.field input:hover ( background-color: rgba(200, 200, 200, 0.8 ); ) #records_list ( text-align:left; ) #records_list .record ( border-top: 1px solid #000000; font-size: 13px; padding: 10px; ) #records_list .record:first-child ( border-top -width:0px; ) #records_list .record p:first-child ( font-weight:bold; font-size:11px; )
PHP 5.2 and above;
- mod_rewrite;

- Database MySQL 4.1 and above.

Opportunities
Embeds under any site (for this you just need to edit the top.php and bottom.php files);
- anti-flood;
- ban list;<< < ...| 5 | 6 | 7 ... > >>;
- page navigation view
- BBCode support;
- display emoticons;
- notification of new added messages;
- the ability to add messages for moderation;
- Easy to install and set up.

Installation

Unzip the archive and copy the contents of the archive to any folder on your web server (eg "guestbook"). Open the config/config_db.php file in a text editor and specify the connection settings (database host or IP, database name, login and password). Place MySQL database tables SQL query from guestbook.sql file. usually on most hostings this is done through the web interface via phpMyAdmin. Go to the administration panel (http://your_site/folder_with_script/admin/) and enter the password 1111. Next, specify the necessary settings.

Commercial version

At the request of the customer, I can adapt the script to specific conditions. Various additional features can be added.

Note

"PHP Guestbook" SCRIPT, THEREFORE JUST THE PROGRAM IS TOTALLY FREE. YOU MAY FREELY DISTRIBUTE, COPY, MAKE YOUR CHANGES IN THE SOURCE CODE OF THE PROGRAM, ONLY UNDER THE CONDITION OF THE AUTHOR'S COPYRIGHT. USE OF "PHP Guestbook" PROGRAM FOR COMMERCIAL PURPOSES IS PROHIBITED. YOUR USE OF THIS PROGRAM IS AT YOUR OWN RISK. THE AUTHOR IS NOT RESPONSIBLE FOR THE PERFORMANCE OF THE PROGRAM, AS WELL AS FOR LOSS, DAMAGE TO DATA OR ANYTHING OR ANYTHING ASSOCIATED WITH THE USE AND OPERATION OF THIS PROGRAM.

If you liked my script and you have a desire to thank me with a ruble, then here are my details:

WebMoney
U237811811298
R198597198920
Z917380288657

Yandex money
41001635943434

PayPal

If you have any questions or suggestions, please write to me at: This email address is being protected from spambots. You must have JavaScript enabled to view.

» DRBGuestbook

The DRBGuestbook is a free, simple PHP script that does not require a MySql database. Despite this, you can manage the program, delete messages, approve messages, ban users by IP address, through a password-protected admin panel. The script also includes anti-spam checks such as image verification, URL blocking, and moderation of all messages in the book. You can set the feature so that every time someone leaves a message, you will be notified by e-mail.

Benefits of the script

  • Quick and easy installation.
  • Does not require a MySQL database. All messages are stored in a file.
  • You can delete multiple messages at once.
  • Contains anti-spam check.
  • You can ban the IP address so that you can not leave messages.
  • Supports post moderation so that only approved posts are published.
  • Get notified by email every time someone subscribes to your guestbook.
  • Checking the message: a list of "forbidden" (swear words) for publication.
  • Anti-flood function. To prevent users from posting so often.
  • The script prevents the publication of HTML codes or links (URL) in the message body, as an anti-spam precaution.
  • Setting the minimum and maximum letters in one message.
  • The script can be easily configured: error messages, warnings, date and time.
  • Date and timezone are easily configurable.
  • The generated pages contain XHTML syntax and work fine in IE and Firefox browsers.
  • Login to the admin panel through the web interface.

System requirements

  • PHP version 4.4 or higher
  • GD library
  • Apache HTTP Server with .htaccess file with Override Allowed feature (recommended)
  • Linux, Windows, Unix, Mac OSX, Sun Solaris, IIS

» » GBook

This PHP script will help you implement the guestbook feature on your website. Without using any MySQL Database, it is not needed for the script to work. The Gbook script includes many powerful SPAM filters. And also protection of mail from SPAMers.

There are 2 txt files in the script - header.txt and footer.txt. With the help of these files, you can add advertising blocks or counters to your guest book. Completely changing the template to fit the style of your site will also not cause much difficulty. The Gbook program can be translated into any language in the world. Just change the words in one file language.

Benefits of the script

  • Emoticon support.
  • Does not require a MySQL database. All messages are stored in a file.
  • Notification of the admin by mail, about a new message in the Guest Book.
  • Contains 2 anti-spam checks.
  • You can ban the IP address so that you can not leave messages.
  • Get notified by email every time someone subscribes to your guestbook.
  • Checking the message: a list of "forbidden" (uncensored) words for publication. Cover ****
  • Anti-flood function. To prevent users from posting so often.
  • Private messages.

A guest book can be a great way for your website visitors to make a permanent impression on their presence on your website without being too intrusive. Before you start thinking about the HTML source for a guestbook, you need to decide how you want it to flow and how you want it look. In this case we will look at a guestbook that places a form for users to sign at the top. Below that there will then be a list of all the comments posted by the readers.

The HTML Source Code

The HTML source for our guestbook will consist of a web form and a list of DIV containers which will hold the display for the signed comments. The Part of the code that will handle the form is a simple as this.

Please Sign Our Guestbook

Right below the form, we will place the comments for other users that have already signed the guestbook and that HTML that handles this looks somewhat like this.

Love your website, I will come back often!!

It was a great experience spending time here, Would love to contribute more!!

Wilbur Right

Great to be a part of what you are doing here!!

Adam Adeve

Wish you all the best and success in your project!

Tony Scott

Keep up the good work!!

The effects of placing these two pieces of HTML code on your Guestbook webpage would be as illustrated in the image shown above on the left.

Making It All Work

As is the custom with HTML, it is not too functional on its own as HTML was designed primarily as a way to handle displays of text and images. To solve this problem, we need to implement some server-side code to process the data collected by the guestbook form. This server-side code could be in any one of a number of programming languages ​​such as PHP, ASP .NET, JSP, or Ruby. Since programming in these languages ​​is beyond the scope of this article, I’m going to use generic, "pseudo" code to represent the server side code and give you an idea of ​​how it might look.

connect to database

if(form submitted)(

insert data into database()

read all guestbook entries from database and order by date descending

while(database entries exist)(

// display entires in this format

print: "

$fullname$
$date$

$message$

."

close connection to database

The pseudo code above simply makes a connection to the database where the data is stored. It then checks to see if the guestbook form has been submitted. If it has, it then enters the data into the database.

The next thing the pseudo code does is read all the guestbook entries from the database and display them to the user right under the web form giving the result as seen in the image above.

Conclusion

There you have it. The HTML source for a guestbook does not get any simpler than that. Guestbooks are one of the easiest and most basic dynamic pages you will ever implement on your website. Of course the guestbook can be styled further and more complex modes of operation and data validation can and should be used to suite the flow of your website. Whichever way you choose to implement the guestbook, the basics as described in the pseudo code remain the same.

Full Name:
Email address
message: