Crazy guestbook html. Guest book script in PHP

💖 Do you like it? Share the link with your friends

Hello site readers)

In this article we will look at Phoca Guestbook - a guest book component for Joomla sites.

What can we say about this component... It is very simple and easy to administer, it has a sufficient number of settings for posting reviews on your website.

Features of Phoca Guestbook:

  • selecting access rights for users;
  • filtering unwanted words and phrases;
  • blocking IP addresses;
  • limiting the number of printed characters;
  • captcha;
  • modernization of messages (checked by a moderator);
  • appearance reviews (color, name display, e-mail display and website address).

So let's look at the component.

Once installed, Phoca Guestbook does not require global settings.

Control Panel:

  • Posts - all messages left by users;
  • Guestbooks - categories (created guest books);
  • Info - Information and component update.

As you can see, in the picture on the right there is a "Options" button. If you click on it, you can more extensively configure the guest book and the component itself.

Parameter

Meaning

Display Subject In Form

(Yes | Yes (required) | No) show or hide the Object field in the form, set if the Subject field is required

Display Name In Form

(Yes | Yes (required) | No) show or hide the field name in the form, set if the Name field is required

Display Email In Form

(Yes | Yes (required) | No) show or hide the e-mail field in the form, set the e-mail field if required

Display Website In Form

(Yes | Yes (required) | No) show or hide the Website field in the form, set the field if a website is required

Display Content In Form

(Yes | Yes (required) | No) show or hide the contents of the field in the form

Enable Javascript Editor

(Yes | No) Enable or disable JavaScript Editor

Display Path In Javascript Editor

(Yes | No) show or hide JavaScript editor path information

(Hide | Display) Set if the form should be displayed or not.

(Top | Bottom) Select Current Location

Display Required Sign

(Yes | No) Set to display fields that are required

(Yes | No) Set to display messages.

width (in pixels)

height (in pixels)

Set the width of the table (the table in which the form is displayed, in pixels)

Parameter

Meaning

If an unregistered user leaves a message, you can give him a default name. For example: Guest

Username Or Name

(Username | First name) select the name that should be displayed in the Guest Book (Username or real username)

Disable User Check

(No | Yes) User verification (disabling this option is not recommended)

Registered Users Only

(Yes | No) If Yes, then only registered users can add new messages

(Yes | No) If yes, the message will be displayed after admin approval

Send a letter

Parameter

Meaning

Display Name In Post

(Yes | No) show or hide name (username) (guestbook)

Display Email In Post

(Yes | No) show or hide email(guest book)

Display Website In Post

(Yes | No) show or hide the site in (guest book)

Set date format

Set font color

Second Font Color

Set second font color (date font color)

Background Color

Set background color

Setting the border color

Pagination Default Value

Set default value for pagination

Set page numbering. Separated by a comma (,)

Pagination Hide All

(Yes | No) all values ​​will be hidden (pagination)

Parameter

Meaning

Forbidden Word Filter

Set prohibited words that will not be displayed in the interface. Words are separated from each other by a comma (,)

Forbidden Whole Word Filter

Set all prohibited words that will not be displayed in the interface. Words are separated from each other by a comma (,)

Save post with forbidden words

(Yes | No) If yes, then posts that include banned words will be saved in the guestbook (banned words will be hidden if saved)

Add the IPs you want to block. Separate each IP with a comma (,)

Maximum Characters

Set the maximum number of characters they can be stored in the database

Install maximum quantity URLs that can be displayed in a post (0: no, links will be shown in posts, -1: all URLs will be shown in posts, e.g. 3: only three links from all URLs will be shown in posts)

Not Allowed URL Identification Words

A set of words that will determine whether URLs are allowed in the message. Separate each word with a comma (,). Example:: / /,. HTM,. ASP. JSP,. PHP, WWW.,. COM,. ORG,.

Enable or disable Captcha protection

Change this parameter only if you will not see the captcha.

Enable Captcha - Users

(All | Not registered) Captcha display option for user groups (whether to show the captcha to registered users)

Standard Captcha Characters

Numbers, lowercase letters, uppercase characters that will be displayed in the standard Captcha image

Math Captcha Characters

Numbers, lowercase letters, uppercase characters that will be displayed in Math Captcha images

TTF Symbols

Numbers, lowercase letters, uppercase characters that will be displayed in TTF Captcha images

TTF Captcha Characters

To display the re-captcha, enter the public code

reCAPTCHA Public Key

Install Public Key recaptcha

Enable Akismet Spam Protection

(No | Yes) Sends all the data of the new geustbook entry to Akismet - a web service for checking spam

Block Spam (Akismet)

(No | Yes) Block posts that are not verified by Akismet

Install the Akismet API key to be used in Akismet-Spam. Get yours at https://akismet.com/signup/ for free

The main URL of your site. (The URL must include the http:// prefix)

Enable HTML Purifier

(No | Yes) Enable or disable HTML Purifier

Set session suffix (This is a security feature, to change the session name, set a unique suffix, for example: a100b20c3)

Enable Hidden Field

(No | Yes) Enable or disable hidden fields. Some spam bots try to fill in all the fields on the spot; if they fill out this hidden field that a person cannot see, the entry will not be added to the guest book.

(Yes | No) Enable cache.

Enable Detecting Incoming Page

(Yes | No) Enable or disable incoming page detection. This is a security feature. If you enable it, the page from which the guest book post came will be saved and displayed in the interface.

I recently received an email asking for help with a script for a guest book or a review book. Therefore, I am keeping my promise and today’s article will be on this topic.

What is a guest book and why is it needed on a website?

A guest book is a kind of book of complaints or wishes, where any visitor to your site can leave a message, which (if approved by the admin) can be read by everyone. Those. These are the most common comments, not just for a single post, but for the whole site!

A guest book adds interactivity to your site and is a common way to provide feedback.

So, first, let's create a table in the mysql database where all user comments will be stored:

CREATE TABLE IF NOT EXISTS `guestbook` (`id` int(11) NOT NULL auto_increment, `user_ip` int(10) unsigned NOT NULL, `user_email` varchar(50) NOT NULL, `addtime` int(11) NOT NULL , `name` varchar(15) NOT NULL, `text` text NOT NULL, `admin_text` text NOT NULL, `image` varchar(40) NOT NULL, `sex` tinyint(1) NOT NULL default "1", PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

  • id — message sequence number
  • user_ip — user IP address, represented as an integer
  • user_email — user email address
  • addtime — message adding time
  • name - user name
  • text — message text
  • admin_text — text of the administrator’s response to the message
  • image — user avatar
  • sex — user gender (male/female)

As you can see in the sign there is a field for the user’s IP address. This is done so that you can then create a blacklist where you can enter the IP addresses of “not good” users who will not be able to leave messages in the future.

The sex field is needed in order to display the “correct” avatar in the event that users do not upload theirs.

We've sorted out the database. Let's move on to programming. Since we are working with a database, the first thing we will do is create the simplest class for working with the database. To do this, create a file DB.class.php and place the following code there:

Class DB ( private static $instance; private $MySQLi; private function __construct(array $dbOptions)( $this->MySQLi = @ new mysqli($dbOptions["db_host"],$dbOptions["db_user"], $dbOptions[ "db_pass"],$dbOptions["db_name"]); if (mysqli_connect_errno()) ( throw new Exception("Database error."); ) $this->MySQLi->set_charset("utf8" ) public static function init(array $dbOptions)( if(self::$instance instanceof self)( return false; ) self::$instance = new self($dbOptions); ) public static function getMySQLiObject())( return self::$ instance->MySQLi; ) public static function query($q)( return self::$instance->MySQLi->query($q); ) public static function esc($str)( return self::$instance-> MySQLi->real_escape_string(htmlspecialchars($str) )

It is worth saying that the constructor of this class is declared private, so the object cannot be created outside the class, and initialization is only possible from the static init() method. It takes an array of MySQL connection parameters and creates an instance of the class, which is contained in the static variable self::$instance. This ensures that there is only one connection to the database at a given time.

The rest of the class performs database queries based on the static query() method.

If you wish, you can modify this class as you need it!

Also, in developing a guest book, we will need auxiliary functions, which I will include in separate file and I'll call it helper.php.

Now we have smoothly approached the most important file in our script - index.php. This is where all the script logic will be executed.

So, the first thing you need to do is initialize the session, set the basic settings and connect to the mysql database. The session will store security code(captcha) forms.

Session_start(); /* Database configuration. Add your data */ $dbOptions = array("db_host" => "localhost", "db_user" => "", "db_pass" => "", "db_name" => ""); //Connect the class for working with the database require "DB.class.php" //Connect auxiliary functions require "helper.php" //Connect to the database DB::init($dbOptions); $appath = realpath(dirname(__FILE__))."/"; //Folder on the server where avatars will be uploaded $uploaddir = "images/avatars"; //Maximum number of messages on one page $per_page = 10; //Number of pages in paging $num_page = 2;

To build navigation through pages in the guest book, you need to find out the total number of messages. This can be done like this:

//Get the total number of messages $result = DB::query("SELECT COUNT(*) AS numrows FROM guestbook"); $total = $result->fetch_object()->numrows;

Now let's determine the page number that needs to be shown. To do this, we will process the variable $_GET["p"]

$start_row = (!empty($_GET["p"]))? intval($_GET["p"]): 0; if($start_row< 0) $start_row = 0; if($start_row >$total) $start_row = $total;

$result = DB::query("SELECT * FROM guestbook ORDER BY addtime DESC LIMIT ".$start_row.",".$per_page); //The list of messages will be stored here $items = array(); while($row = $result->fetch_assoc())( $row["addtime"] = format_date($row["addtime"],"date")."|".format_date($row["addtime"] "time"); $items = $row;

Here I have used format_date() function to work with date and time which I have created in helper.php file. Its main task is to display the date and time in Russian format. Here is its code:

Function format_date($date,$format = "date")( if(empty($date)) return ""; $months = array("1" => "January", "2" => "February", " 3" => "March", "4" => "April", "5" => "May", "6" => "June", "7" => "July", "8" => " August", "9" => "September", "10" => "October", "11" => "November", "12" => "December"); if($format == "time") ( return date("H:i",$date); ) elseif($format == "date")( $m = date("n", $date); $m = $months[$m]; $ d = date("j",$date); $y = date("Y",$date); return $d." ".$m." ".$y; ) else( return date("d.M.Y H :i",$date); ) )

This function has only 2 parameters:

  • $date — date in UNIX format (number of seconds passed since the night of January 1, 1970)
  • $format — date output form.

Now we can display a list of messages on the page. For this I use the following html code:

Guestbook Reviews leave a review

Tell friends