PHP Classes

File: tutorial.txt

Recommend this page to a friend!
  Classes of Benjamin Falk   Flood Assassin   tutorial.txt   Download  
File: tutorial.txt
Role: Documentation
Content type: text/plain
Description: Just a quick tutorial
Class: Flood Assassin
Check whether a message can be spam
Author: By
Last change: just changed the tutorial-link
Date: 14 years ago
Size: 3,121 bytes
 

Contents

Class file image Download
Tutorial In many cases, the implementation of modules is really difficult. For that reason I created this little tutorial to support you. So let's beginn. At first, you need to download the php-file floodassassin.php under Download. Get the full package and extract it, whereever you want to use it. Now let's beginn with the code. We need a little configuration-file, with the data of your MySQL-Database. <?php $sqlHost = 'localhost'; //Default is localhost $sqlUsername = 'root'; //Type here your username $sqlPassword = 'root'; //The password $sqlDatabase = 'floodassassin'; //Your database $sqlTable = 'floodrules'; //The databasetable /* For this tutorial we have a table called floodrules. */ ?> Save that code above as configuration.php in the same directory as floodassassin.php. Get your database filled up. In your package should be a dummy.sql file. Upload it in your phpMyAdmin (same database, as in the configuration-file). The dummy.sql also includes some basic rules. If you alread got an old version do the same but with update-dummy.sql. Now it's time to talk about the main usage of floodassassin.php. Let's say, there was a Form on the previous page, with 3 input-fields. field_content, field_name and field_mail. The mail-field is optional <?php /* At first, we need to call the floodassassin-file */ require_once 'floodassassin.php'; if (isset($_POST['field_content']) && isset($_POST['field_name'])) { //Only initialize the FLOODASSASIN-class, if needed $objFloodAssassin = new FLOODASSASSIN(); $content = $_POST['field_content']; $name = $_POST['field_name']; $mail = isset($_POST['field_mail']) ? $_POST['field_mail']:''; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR']:''; $result = $objFloodAssassin->checkMessage($content, $name, $mail, $ip); /* Now $result should be an array [0] => Messagelevel. The higher the bigger the chance of spam [1] => Messagelevels. All levels [2] => Descriptions. The description of the levels */ if ($result[0] >= 3) { //It seems, that the message is spam. //Do whatever you want } else { //It seems clear //Do whatever you want } } ?> So for example the content of the message is the following: Hello Jo! Your pictures are great! The result of this text would be the following: Array ( [0] => 2.4 [1] => Array ( [0] => -0.1 [1] => 0.5 [2] => 2 [3] => 0 [4] => 0 ) [2] => Array ( [0] => HELLO [1] => NOT READABLE [2] => SMALL TEXT [3] => LINKS (0) [4] => MAILS (0) ) ) See also http://www.floodassassin.org/tutorial.php