dbc = mysql_connect($server, $user, $password) or die ("Connection failed!"); mysql_select_db($database) or die ("Database failed!"); } /* DISPLAY RECORDS */ function display_records($offset, $entries_per_page) { $this->result = mysql_query("SELECT id, name, email, message, date FROM $this->table ORDER BY id DESC LIMIT $offset, $entries_per_page") or die ("Query failed!"); while ($row = mysql_fetch_array($this->result)) { // SOME NICE FORMATTING HERE; $display_name = nl2br(htmlspecialchars($row["name"])); $display_email = nl2br(htmlspecialchars($row["email"])); $display_message = nl2br(htmlspecialchars($row["message"])); // THIS ALLOWS USING SMILIES AND IS NOT DANGEROUS; $display_message = str_replace ("<img src=smiles/", "", $display_message); // DISPLAY WHAT WE HAVE AT LAST; echo "

" . $display_name . ", " . $row["date"] . "

" . "Email: " . $display_email . "

" . $display_message . "

"; } /******************************************************************************/ /* This code here handles pages stuff, number and next/previous links, etc. */ /* If you don't need some of the features, just delete corresponding parts. */ /******************************************************************************/ $this->count_result = mysql_query("SELECT count(id) AS number FROM $this->table") or die ("Query failed!"); while ($count = mysql_fetch_array($this->count_result)) { $total_entries = $count["number"]; } // HOW MANY PAGES OF RECORDS WE HAVE; // THIS BLOCK IS ESSENTIAL FOR FURTHER PARTS; $pages = $total_entries / $entries_per_page; if ($pages < 1) { $pages = 1; } if ($pages / (int) $pages <> 1) { $pages = (int) $pages + 1; } else { $pages = $pages; } if (($offset > $total_entries) or (!is_numeric($offset))) $offset = 0; // CURRENT PAGE NUMBER; $pagenow = ($offset/$entries_per_page + 1); echo "


* * *
Seite " . $pagenow . " von " . $pages; // NEXT/PREVIOUS PAGE LINKS DISPLAY $next = $offset + $entries_per_page; $previous = $offset - $entries_per_page; if ($pages <> 1) { echo " || "; if ($previous < 0) { echo ""; echo ">>>"; } elseif ($next >= $total_entries) { echo ""; echo "<<<"; } else { echo ""; echo "<<<"; echo " | "; echo ""; echo ">>>"; } echo "

"; } // DISPLAY LINKS TO ALL PAGES SEPARATELY; echo "
Seiten: "; $i = 0; while ($i < $pages) { $ri = $i + 1; $showpage = $i * $entries_per_page; if ($ri == $pagenow) echo $ri . " "; else echo "" . $ri . " "; $i++; } echo "
"; } /******************************************************************************/ /* End of pages code, this section is the longest, but you get pages features */ /******************************************************************************/ /* ADD RECORDS TO DATABASE */ function add_record($name, $email, $message, $smilies="on", $webmaster, $message_length, $language_filter, $bad_words) { if ($email == "") { $email = "no_email"; } // IF LANGUAGE FILTER IS ENABLED AND WEBMASTER EMAIL ADDRESS DEFINED DO THIS; if (($language_filter == 1) and (strlen($webmaster) <> 0)) { for ($i=0;$i 0) { $message = substr($message, 0, $message_length); } // IF USER USES SMILIES DO THIS; if ((isset($smilies)) and ($smilies == "on")) { $format_smilies = array ( ":-)", "\'Smile\'", "8-)", "\'Glasses\'", ":(", "\'Angry\'", ":-D", "\'Big", "%-)", "\'I", ">8-|", "\'Evil\'", ":-o", "\'Kiss", "?", "\'Question\'", ":-(", "\'Sad\'", "[$-)", "\'Sleepy\'", ":-P", "\'Tongue\'", ";-)", "\'Wink\'" ); for ($i=0;$iresult = mysql_query("INSERT INTO $this->table (name, email, message, date) VALUES ('$name', '$email', '$message', NOW())"); // When guestbook is signed a message is emailed // to webmaster if this feature is enabled; if (strlen($webmaster) <> 0) { $sendmessage = "Name: " . $name . "\nEmail: " . $email . "\nMessage: " . $message; @mail($webmaster, "Guestbook www.projektb.net signed", $sendmessage); } if (!$this->result) echo "Error!"; } /* DISCONNECT FROM DATABASE */ function disconnect_db() { mysql_close($this->dbc); } } /******************************************************************************/ /* END OF GUESTBOOK CLASS */ /******************************************************************************/ /******************************************************************************/ /* INSTALLATION: */ /* 1) create a table in the MYSQL database with a query: */ /* CREATE TABLE guestbook ( */ /* id int(5) NOT NULL auto_increment, */ /* name varchar(50), */ /* email varchar(50), */ /* message text, */ /* date datetime, */ /* PRIMARY KEY (id) */ /* ) */ /* 2) define some variables below as they suit your environment; */ /* 3) possibly change any formatting in the display_records() function; */ /* 4) copy gb.php to your server and enjoy; */ /******************************************************************************/ // Let's define some variables; $webmaster = 'alex@projektb.org'; // EMAIL ADDRESS TO SEND WARNINGS TO // WHEN GUESTBOOK IS SIGNED; LEAVE // EMPTY IF YOU WANT THIS FEATURE // DISABLED; $server = 'mysql.roterschnee.com'; // DATABASE SERVER; $database = 'projektb_org'; // DATABASE NAME; $user = 'projektb_org'; // USER TO CONNECT TO DATABASE; $password = 'st4r24b'; // USER PASSWORD; $entries_per_page = 5; // HOW MANY RECORDS PER PAGE; $message_length = 1024; // MESSAGE LENGTH ALLOWED, LEAVE 0 // IF YOU WANT ANY SIZE MESSAGES, // THIS CUTS MESSAGE TO DEFINED SIZE; $language_filter = 0; // 1 - enable language filter; // 0 - disable language filter; $bad_words = array ( // Bad words vocabulary (add your own); 'fuck', 'cunt', 'asshole', 'dick', 'pussy', 'bitch', 'motherfucker', 'nigger' ); // Let's spawn an instance of guestbook class; $myGB = new Guestbook; $myGB->connect_db($server, $database, $user, $password); // If user submitted form, add a record; if (isset($message)) { if (!isset($smilies)) $myGB->add_record($name, $email, $message, "no", $webmaster, $message_length, $language_filter, $bad_words); else $myGB->add_record($name, $email, $message, $smilies, $webmaster, $message_length, $language_filter, $bad_words); } // If opened without $offset variable defined, it is zero; if ((!isset($offset)) or ($offset < 0) or (!is_numeric($offset))) $offset = 0; $myGB->display_records($offset, $entries_per_page); $myGB->disconnect_db(); ?>