Gå til innhold

Spam filter på min shoutbox.


Anbefalte innlegg

Jeg har en shoutbox på sida mi: http://www.kg.hotserv.dk

 

Men tror det skal være innebygd spam filter men jeg tror ikke det fungerer.

 

Det SKAL fungere slik:

 

Ip'en til hver enkelt person som poster i shoutboxen bli logga (det blir den). Så må det gå 20 sekund elns for de kan poste igjen. Men hvis den samme ip'en poster 5-10 poster på rad så bli de banna fra sida 1-2 dager. Men jeg tviler den fungerer. Har testa men nei.

Lenke til kommentar
Videoannonse
Annonse

Ja det var enkel, og ja jeg trenger hjelp og jeg kan poste koder:

 

config.inc.php

 

<?
//========================================================================================================
// Database settings
//========================================================================================================

 $db_server = "db01";      // server name
 $db_user = "hemmelig";             // user name
 $db_pass = "hemmelig";                 // user password
 $db_name = "hemmelig";                 // database name

 // don't change unless you know what you're doing:
 $ip = $_SERVER['REMOTE_ADDR']; //ip adresse
 $tbl_name = "Shoutbox";        // table name
 $fld_id = "ID";                // field name: ID
 $fld_timestamp = "Timestamp";  // field name: timestamp
 $fld_name = "Name";            // field name: name
 $fld_email = "EMail";          // field name: e-mail
 $fld_text = "Text";            // field name: text
 $fld_ip = "ip";                // field name: ip
 
 

//========================================================================================================
// Other settings
//========================================================================================================

 $language = "de";              // shout-box language: de, en, fr
 $boxFolder = "http://www.kg.hotserv.dk/shoutbox";               // shout-box folder (web-path)
 $boxWidth = 192;               // shout-box width (pixels)
 $boxHeight = 400;              // shout-box height (pixels)
 $boxEntries = 9999;              // maximum entries in shout-box (higher values = more traffic!)
 $boxRefresh = false;              // refresh shout-box every .. seconds (lower values = more traffic!)
 $messageOrder = "ASC";        // message order: ASC (new at bottom) or DESC (new on top)
 $allowHTML = false;            // allow HTML-code in message (true = yes, false = no)
 $wordLength = 30;              // maximum word length (insert spaces into loooooong words; 0 = off)
                                // NOTE: should be 0 for non-European languages (Asian, Arabic, etc.)
 // bad words
 $nonos = array("fuck", "asshole", "dickhead", "kuk");

//========================================================================================================
?>

 

 

lang_de.inc

 

<?
 $msg['name']    = " Navn";
 $msg['eMail']   = " E-Post";
 $msg['message'] = " Melding";
 $msg['smilies'] = "Smilyer";
 $msg['refresh'] = "Oppdater";
 $msg['shout']   = "Shout!";
?>

 

 

Shout.php

 

<?
 error_reporting(E_WARNING);

//========================================================================================================
// Cookies
//========================================================================================================

 if(isset($Name)) {
   $shouter = $Name;
   setcookie('shouter', $shouter);
 }
 if(isset($EMail)) {
   $shouter_mail = $EMail;
   setcookie('shouter_mail', $shouter_mail);
 }

//========================================================================================================
// Includes
//========================================================================================================

 include('config.inc.php');
 include('smilies.inc');

//========================================================================================================
// Set variables, if they are not registered globally; needs PHP 4.1.0 or higher
//========================================================================================================

 if(!isset($Name)) $Name = $_REQUEST['Name'];
 if(!isset($EMail)) $EMail = $_REQUEST['EMail'];
 if(!isset($Text)) $Text = $_REQUEST['Text'];

//========================================================================================================
// Functions
//========================================================================================================

 function db_connect() {
   global $db_name, $db_server, $db_user, $db_pass;

   $status = true;
   if(!@mysql_connect($db_server, $db_user, $db_pass)) {
     echo '<font color=red>' . mysql_errno() . ': ' . mysql_error() . '</font><br>';
     $status = false;
   }
   else if(!@mysql_select_db($db_name)) {
     echo '<font color=red>' . mysql_errno() . ': ' . mysql_error() . '</font><br>';
     $status = false;
   }
   return $status;
 }

 function timeStamp($ts) {
   return substr($ts, 0, 4) . '-' . substr($ts, 4, 2) . '-' . substr($ts, 6, 2) . ' ' . substr($ts, 8, 2) . ':' . substr($ts, 10, 2) . ':' . substr($ts, 12);
 }

 function checkRepeats($str) {
   $newstr = substr($str, 0, 3);

   for($i = 3; $i < strlen($str); $i++) {
     if($str[$i] == $str[$i-1] && $str[$i] == $str[$i-2] && $str[$i] == $str[$i-3]) continue;
     else $newstr .= $str[$i];
   }
   return $newstr;
 }

 function checkLongWords($str) {
   global $wordLength;

   if($wordLength && strlen($str) > $wordLength) {
     $words = explode(' ', $str);
     $str = '';

     for($i = 0; $i < count($words); $i++) {
       if(!eregi('&[#a-z0-9];', $words[$i])) $str .= chunk_split($words[$i], $wordLength, ' ');
       else $str .= $words[$i];
     }
   }
   return $str;
 }

 function replaceNonos($str) {
   global $nonos;

   for($i = 0; $i < count($nonos); $i++) {
     $repl = substr('********************', 0, strlen($nonos[$i]));
     $word = chunk_split($nonos[$i], 1, ' *');
     $str = preg_replace('/' . substr($word, 0, strlen($word) - 2) . '/i', $repl, $str);
   }
   return $str;
 }

 function format($str, $sm_code = '', $sm_img = '') {
   global $allowHTML;

   if(!$allowHTML) {
     $str = str_replace('>', '>', $str);
     $str = str_replace('<', '<', $str);
   }
   $str = eregi_replace('http://', '', $str);
   $str = checkRepeats($str);
   $str = checkLongWords($str);
   $str = replaceNonos($str);
   if($sm_code && $sm_img) $str = str_replace($sm_code, $sm_img, $str);

   return $str;
 }

//========================================================================================================
// Main
//========================================================================================================

 if(db_connect()) {
   $error = '';


?>
   <html>
   <head>
   <meta http-equiv="refresh" content="<? echo $boxRefresh; ?>; URL=<? echo basename($PHP_SELF); ?>">
   <title>Output</title>
<?
   $messageOrder = strtoupper($messageOrder);
   if($messageOrder != 'ASC' && $messageOrder != 'DESC') $messageOrder = 'DESC';

   if($messageOrder == 'ASC') {
?>
     <script language="JavaScript"> <!--
     function autoscroll() {
       if(document.body && document.body.offsetHeight) window.scrollBy(0, document.body.offsetHeight);
       else if(window.innerHeight) window.scrollBy(0, window.innerHeight);
       else if(document.height) window.scrollBy(0, document.height);
     }
     window.onload = autoscroll;
     //--> </script>
<?
   }
?>
   <link rel="stylesheet" href="shoutbox.css" type="text/css">
   </head>
   <body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>
<?
   if($Text) {
     $tstamp = date('YmdHis');
     $sql = "INSERT INTO $tbl_name ($fld_timestamp, $fld_name, $fld_email, $fld_text, $fld_ip) ";
     $sql .= "VALUES ('$tstamp', '$Name', '$EMail', '$Text', '$ip')";
     if(!mysql_query($sql)) $error .= mysql_error() . '<br>';

     $sql = "SELECT $fld_id FROM $tbl_name ORDER BY $fld_timestamp DESC LIMIT 1";
     $id = mysql_result(mysql_query($sql), $fld_id) - $boxEntries;
     if($id > 0) {
       $sql = "DELETE FROM $tbl_name WHERE $fld_id<=$id";
       if(!mysql_query($sql)) $error .= mysql_error() . '<br>';
     }
   }
?>
   <table border=0 cellspacing=0 cellpadding=2 width=100%><tr>
   <td>
<?
   if($error) echo "<font color=red>$error</font><br>";
?>
   <table border=0 cellspacing=0 cellpadding=0 width=100%>
<?
   $sm_code = $sm_img = array();

   while(list($code, $img) = each($sm)) {
     $sm_code[] = $code;
     $sm_img[] = "<img src='smilies/$img' width=15 height=15 align=top>";
   }

   $sql = "SELECT * FROM $tbl_name ORDER BY $fld_timestamp $messageOrder LIMIT $boxEntries";
   $result = mysql_query($sql);

   while($row = mysql_fetch_array($result)) {
     $tstamp = timeStamp($row[$fld_timestamp]);
     $name = $row[$fld_name] ? format($row[$fld_name]) : '?';
     $email = $row[$fld_email];
     $text = format($row[$fld_text], $sm_code, $sm_img);
     $bgcolor = ($bgcolor != '#FFFFFF') ? '#FFFFFF' : '#F6F6F6';
?>
     <tr bgcolor=<? echo $bgcolor; ?>>
     <td class="cssSmall" align=right><font color=#A0A0A0><? echo $tstamp; ?></font></td>
     </tr><tr bgcolor=<? echo $bgcolor; ?>>
     <td class="cssShoutText"><? if($email) echo '<a href="mailto:' . $email . '">'; ?>
     <b><? echo $name; ?>:</b><? if($email) echo '</a>'; ?> <? echo $text; ?></td>
     </tr>
<?
   }
   mysql_close();
?>
   </table>
   </td>
   </tr></table>
   </body>
   </html>
<?
 }
?>

 

 

Shoutbox.css

 

A, A:active, A:visited {
 color: black;
}
A:hover {
 color: red;
}
.cssShoutBox {
 border: 2px inset #EEEEEE;
}
.cssShoutForm {
 font-family: Arial, Helvetica;
 font-size: 11px;
 background-color: #FFFFFF;
 border: 2px inset #EEEEEE;
}
.cssShoutButton {
 font-family: Arial, Helvetica;
 font-size: 11px;
}
.cssShoutText {
 font-family: Arial, Helvetica;
 font-size: 11px;
}
.cssSmall {
 font-family: Arial, Helvetica;
 font-size: 9px;
}

 

 

shoutbox.inc.php

 

<?
 error_reporting(E_WARNING);

//========================================================================================================
// Includes
//========================================================================================================

 $this_dir = str_replace('\\', '/', dirname(__FILE__));

 include("$this_dir/config.inc.php");
 if(!isset($language)) $language = 'en';
 include("$this_dir/lang_$language.inc");
 include("$this_dir/smilies.inc");

//========================================================================================================
// Main
//========================================================================================================

 $input_width = round($boxWidth / 10);

 if($boxFolder && !ereg('/$', $boxFolder)) $boxFolder .= '/';
?>
<script language="JavaScript"> <!--
var shout_popup = 0;

function newWindow(url, w, h, x, y, scroll, menu, tool, resizable) {
 if(shout_popup && !shout_popup.closed) shout_popup.close();
 if(!x && !y) {
   x = Math.round((screen.width - w) / 2);
   y = Math.round((screen.height - h) / 2);
 }
 shout_popup = window.open(url, "shout_popup", "width=" + w + ",height=" + h +
                           ",left=" + x + ",top=" + y + ",scrollbars=" + scroll +
                           ",menubar=" + menu + ",toolbar=" + tool + ",resizable=" + resizable);
 shout_popup.focus();
}

function refreshBox() {
 document.fShout.Text.value = '';
 document.fShout.submit();
 setTimeout("document.fShout.Refresh.disabled=false", 1000);
}

function shoutIt() {
 document.fShout.submit();
 setTimeout("document.fShout.Text.value=''", 1000);
 setTimeout("document.fShout.Shout.disabled=false", 1000);
}
//--> </script>
<link rel="stylesheet" href="<? echo $boxFolder; ?>shoutbox.css" type="text/css">
<table border=0 cellspacing=0 cellpadding=0 align=center><tr>
<td colspan=2 align=center>
<iframe name="ShoutBox" src="<? echo $boxFolder; ?>shout.php" class="cssShoutBox" width=<? echo $boxWidth; ?> height=<? echo $boxHeight; ?> frameborder=0></iframe>
</td>
</tr>
<form name="fShout" action="<? echo $boxFolder; ?>shout.php" target="ShoutBox" method=post>
<tr>
<td class="cssShoutText"><? echo $msg['name']; ?>:</td>
<td align=right><input type=text name="Name" size=<? echo $input_width; ?> maxlength=20 class="cssShoutForm" value="<? echo $shouter; ?>"></td>
</tr><tr>
<td colspan=2 align=center>
 <table border=0 cellspacing=0 cellpadding=0 width=100%><tr>
 <td class="cssShoutText"><? echo $msg['message']; ?>:</td>
 <td align=right><input type=button value="<? echo $msg['smilies']; ?>" class="cssShoutButton" onClick="newWindow('<? echo $boxFolder; ?>smilies.php', 130, 300, 0, 0, 1)"></td>
 </tr></table>
 <textarea name="Text" cols=22 rows=3 style="width:100%" wrap=virtual class="cssShoutForm"></textarea>
 <table border=0 cellspacing=0 cellpadding=0 width=100%><tr>
 <td><input type=button name="Refresh" value="<? echo $msg['refresh']; ?>" class="cssShoutButton" onClick="this.disabled=true; refreshBox()"></td>
 <td align=right><input type=button name="Shout" value="<? echo $msg['shout']; ?>" class="cssShoutButton" onClick="this.disabled=true; shoutIt()"></td>
 </tr></table>
</td>
</tr>
</form>
</table>

 

 

shoutbox.sql

 

# ======================================================================
# MySQL-Dump
# ======================================================================

#
# Table structure 'Shoutbox'
#

CREATE TABLE Shoutbox (
 ID int(10) NOT NULL auto_increment,
 Timestamp varchar(14) NOT NULL,
 Name varchar(20),
 EMail varchar(75),
 Text text NOT NULL,
 PRIMARY KEY (ID)
);

 

 

smilies.inc

 

<?
 $sm[':))'] = $sm[':-))'] = $sm[':D'] = $sm[':-D'] = 'biggrin.gif';
 $sm[':)'] = $sm[':-)'] = 'smile.gif';
 $sm[';)'] = $sm[';-)'] = 'wink.gif';
 $sm[':/'] = $sm[':-/'] = 'unsure.gif';
 $sm[':['] = $sm[':-['] = $sm[':('] = $sm[':-('] = 'sad.gif';
 $sm[':P'] = $sm[':-P'] = 'tongue.gif';
 $sm[':o'] = $sm[':-o'] = 'surprised.gif';
 $sm[':x'] = $sm[':-x'] = 'angry.gif';
 $sm[':|'] = $sm[':-|'] = 'neutral.gif';
 $sm['->'] = $sm['=>'] = $sm['->'] = $sm['=>'] = 'arrow.gif';

 $sm[':blush:'] = 'blush.gif';
 $sm[':confused:'] = 'confused.gif';
 $sm[':cool:'] = 'cool.gif';
 $sm[':cry:'] = 'cry.gif';
 $sm[':eek:'] = 'eek.gif';
 $sm[':evil:'] = 'evil.gif';
 $sm[':exclaim:'] = 'exclaim.gif';
 $sm[':glad:'] = 'glad.gif';
 $sm[':idea:'] = 'idea.gif';
 $sm[':lol:'] = 'lol.gif';
 $sm[':naughty:'] = 'naughty.gif';
 $sm[':question:'] = 'question.gif';
 $sm[':roll:'] = 'rollseyes.gif';
 $sm[':smirk:'] = 'smirk.gif';
 $sm[':tired:'] = 'tired.gif';
 $sm[':zonked:'] = 'zonked.gif';
?>

 

 

Smilies.php

 

<?
 error_reporting(E_WARNING);

//========================================================================================================
// Includes
//========================================================================================================

 include('config.inc.php');
 if(!isset($language)) $language = 'en';
 include("lang_$language.inc");
 include('smilies.inc');

//========================================================================================================
// Main
//========================================================================================================
?>
<html>
<head>
<title><? echo $msg['smilies']; ?></title>
<script language="JavaScript"> <!--
function insert(txt) {
 if(window.opener) {
   el = window.opener.document.fShout.Text;
   if(!el.value) el.value = txt + ' ';
   else el.value += ((el.value.charAt(el.value.length-1) == ' ') ? '' : ' ') + txt + ' ';
   self.close();
 }
}
//--> </script>
<link rel="stylesheet" href="shoutbox.css" type="text/css">
</head>
<body leftmargin=5 topmargin=5 marginwidth=5 marginheight=5>
<table border=0 cellspacing=0 cellpadding=4 align=center>
<?
 while(list($code, $img) = each($sm)) {
   if($img != $img_old) {
     $bgcolor = ($bgcolor != '#E0E0E0') ? '#E0E0E0' : '#F0F0F0';
?>
     <tr bgcolor=<? echo $bgcolor; ?>>
     <td><a href="javascript:insert('<? echo $code; ?>')">
     <img src="smilies/<? echo $img; ?>" border=0 width=15 height=15></a></td>
     <td class="cssShoutText"><b><? echo $code; ?></b></td>
     </tr>
<?
   }
   $img_old = $img;
 }
?>
</table>
</body>
</html>

 

 

Og så er det en mappe som alle smilyene ligge i.

 

Håper noen har efarginer som kan være til hjelp til meg :w00t:

Lenke til kommentar

Hei igjen

 

Ikkje veldig vanligt å få hjelp me ferdigscript. E sikkert ein faq liksom. Men nå har eg faktisk sett kjapt gjennom kodingen. Ikkje smileys- og css. Eg ser kje någe spamfilter der eg. Kan ver eg har oversett någe. Kanskje du ska skjekka faqen. Ska kje ver så vanskligt å laga men. Kan f.eks. laga ein cookie som level i 20 sekunder...

Lenke til kommentar

Kan du hjelpe meg med deg?? :blush::p Men det kan jo være at noen "spammere" har deaktivert cookies, så kan det gå an att ip'ene blir lagret i MySQL så blir de sletta etter en stund, så mens de ligger i Tabbellen i MySQL så mens ip'ene er der så har de ikke mulighet for å poste i shoutboxen? Men da blir det sikkert mye "trafikk" på Databasen. Så det beste vil vel kanskje være Cookies eller hva?

 

Jeg er ikke så flink på PHP HTML og sånt, men det kan godt hende det ikke er innebygd spam filter.

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...