Guest book script in PHP. Web design and search engine optimization Installation and Russification of Phoca Guestbook

» » @lexGuestbook

@lex Guestbook is free PHP guestbook script for websites. Written on PHP language, @lexGuestbook Easy to install in minutes, even beginners will find it easy to understand.

PHP guestbook A completely free script - the main condition: do not remove the copyright at the bottom of the page. PHP guestbook is installed on your server and is completely independent from any other sites. Backup message in PHP guestbook at your request, at least every day. Automatic installation Alex Guestbook: the names of the tables in the database are written themselves.

Benefits of the script.
  • Thanks to skins, you can change the appearance of @lexGuestbook to suit the design of your website. (all skins are valid XHTML 1.0 Transitional)
  • There are about 20 languages ​​built into PHP guestbook.
  • Each country has its own flag.
  • Support for emoticons: the ability to add your own emoticons, delete, edit.
  • Character statistics are displayed: you can set the maximum number of letters in one message.
  • Internal search engine.
  • Possibility of evaluation by visitors. Score on a 10-point system.
Supported languages

Full translation.
French, English, Polish, German, Norwegian, Italian, Dutch, Slovak, Persian, Turkish.

Partial translation. Some words are still in English.
Spanish, Russian, Swedish, Czech, Croatian, Portuguese, Icelandic, Serbian, Danish.

For HTML codes, guestbook programming might seem unchallenging at first, and rightly so. When you see a guestbook, basic information is requested and it appears that anyone with a fundamental knowledge of the HTML programming language can write guestbook HTML codes. However, guestbooks, from the best to the worst, require a bit more skill than you think.

What is a Guestbook?

A guestbook is an online way to let visitors to your site comment or request information. Most guestbooks post what is written to the webpage so that everyone can read guest comments. The most common items you see on a guestbook are:

  • Name or Username
  • Where they reside (though you can set the HTML code to hide this fact)
  • Email (again, you can hide this fact and have it sent only to your email for communication purposes
  • Comments
  • Some guestbooks forego a comments section for a quick survey. You can usually find questions like "What did you think of this site: good, decent, bad, awesome" or "Was the information provided: enough, not enough, just right"
  • Options to request a reply or other information
Related Articles

Guestbooks can be programmed to send this information to an email address of your choice so that you don"t have to continuously log into the site to view guestbook entries.

Where to Find HTML Codes, Guestbook

Whether you know HTML programming, you are a beginning web designer or you simply want a guestbook on your site, using prewritten HTML codes can save you time. The codes you can find online are typically well-tested and provide the most basic programming needed for easy-to-use guestbooks.

  • The code at HTML Comment Box provides the basic outline of an HTML code guestbook. All you need to do is customize the text to your needs and for your domain name. Instructions are provided at the beginning of the page. The code includes lines for name and address.
  • For a large selection of HTML codes and scripts, visit . With such a varied and large selection, you should be able to find one that works into the website you are creating. You can choose from basic guestbooks to more advanced programming that includes drop down menus and code for Macs and Linux machines. The codes are only 30-day free trials, so if you find a set of codes you like you"ll have to pay for the full use.
  • At Freebok you can input some basic information about what text you want on your guestbook and the website will generate the code for you. Afterwards, you can customize the guestbook even more by creating a template and editing the code in Freebok's template layout mode. Other instructions are available on the site to help you with certain links you may need. You do need to sign up for an account in order to use Freebok.
  • To quickly add a guestbook with just a comment box, go to Guestbook Code. The initial code is already generated, but there are five options you can check and uncheck in order to alter the code slightly:
    • Collapse Guest Book. This includes a link that can open and close the guestbook on the webpage you insert it on.
    • Put Guest Book At Top. If this is unchecked, the guestbook and comment box will appear below any entries in the list.
    • Show Submission Date of Entries. This will add a date and time. The time will be the user's local time zone, not yours.
    • Profanity Filter. Deletes any profanities that people may write.
    • You can also change the number of comments that are posted to the page for others to read. Minimum is one and maximum is one hundred. It"s recommended that you set it between five to twenty-five.

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 the guest book, we will need auxiliary functions, which I will put in a separate file and 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

mob_info