Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Recomandare drona

Exista un soft care sa reia autom...

Identificare plante

Cum declari o variabila care nu s...
 Schimbare certificat de inmatricu...

Poligon auto București

nelamurire legata de pret la mode...

Hotel cu restaurant si Demipensiu...
 Croaziera in Mediterana de Vest 1...

Copilot are pica pe Vladimir Putin

MicroSoft Edge: Cum pun Google in...

Dashcam
 Mini server - VMware

betano.ro

Poveste fara sfarșit

I-auziti voi! - nu vor romani...
 

probleme spam guest book

- - - - -
  • Please log in to reply
16 replies to this topic

#1
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
salut. am si eu o problema. am un guest book pe site care imi este invadat cu mesaje spam....si as dori sa stiu si eu cum introduc un cod captha la acest script...sau ce trebuie sa adaug ca sa banez unele ip-uri ca sa nu se mai poata posta de la ele...va multumesc si astept un raspuns de la voi...scriptul este cel de mai jos...

<?php
/**
* Max's Guestbook
*
* This is the Max's Guestbook business logic class.
* For more details please read the readme.txt
*/
?>
<?php
class maxGuestbook{
   var $messageDir = 'messages';
   var $dateFormat = 'Y-m-d g:i:s A';
   var $itemsPerPage = 5;
   var $messageList;
  
function processGuestbook(){
   if (isset($_POST['submit'])) {
      $this->insertMessage();
   }
   $page = isset($_GET['page']) ? $_GET['page'] : 1;
  
   $this->displayGuestbook($page);
}
  
function getMessageList(){

   $this->messageList = array();
  
// Open the actual directory
if ($handle = @opendir($this->messageDir)) {
// Read all file from the actual directory
while ($file = readdir($handle))  {
    if (!is_dir($file)) {
       $this->messageList[] = $file;
       }
}
}

rsort($this->messageList);

return $this->messageList;
}  

function displayGuestbook($page=1){
      $list = $this->getMessageList();
      //echo "<center><a href='add.php'>Leave a message</a></center>";
      echo "<table class='newsList'>";
      
      //Get start point and end point
      $startItem = ($page-1)*$this->itemsPerPage;
      if (($startItem + $this->itemsPerPage) > sizeof($list)) $endItem = sizeof($list);
      else $endItem = $startItem + $this->itemsPerPage;
      
      for ($i=$startItem;$i<$endItem;$i++){
         //foreach ($list as $value) {
         $value = $list[$i];
       $data = file($this->messageDir.DIRECTORY_SEPARATOR.$value);
       $name  = trim($data[0]);
       $email = trim($data[1]);
         $submitDate = trim($data[2]);
         unset ($data['0']);
         unset ($data['1']);
         unset ($data['2']);
      
         $content = "";
         foreach ($data as $value) {
            $content .= $value;
         }
      
       echo "<tr><th align='left'><a href=\"mailto:$email\">$name</a></th>
                 <th class='right'>$submitDate</th></tr>";
       echo "<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>";
      }
      echo "</table>";
      if (sizeof($list) == 0){
         echo "<center><p>No messages at the moment!</p><p>&nbsp;</p></center>";
      }
      // Create pagination
      if (sizeof($list) > $this->itemsPerPage){
         echo "<div id=\"navigation\">";
         if ($startItem == 0) {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
            } else {
               // Nothing to display
            }
         } else {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
            } else {
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
            }
         }
        
         echo "<br/></div><br/>";
      }
      echo "<hr />";
      $this->displayAddForm();
}

function displayAddForm(){
?>  
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Name:<br/>
    <input type="text" name="name" size="30"/><br/><br/>
    Email:<br/>
    <input type="text" name="email" size="30"/><br/><br/>
    Your message:<br/>
    <textarea name="message" rows="7" cols="49"></textarea><br/>
    <center><input type="submit" name="submit" value="Save" /></center>
  </form>
  
<?php  
}

function insertMessage(){
   $name   = isset($_POST['name']) ? $_POST['name'] : 'Anonymous';
   $email  = isset($_POST['email']) ? $_POST['email'] : '';
   $submitDate  = date($this->dateFormat);
   $content = isset($_POST['message']) ? $_POST['message'] : '';
  
   if (trim($name) == '') $name = 'Anonymous';
   if (strlen($content)<5) {
      exit();
   }
  
   $filename = date('YmdHis');
   if (!file_exists($this->messageDir)){
      mkdir($this->messageDir);
   }
   $f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");        
   fwrite($f,$name."\n");
   fwrite($f,$email."\n");
   fwrite($f,$submitDate."\n");
   fwrite($f,$content."\n");
   fclose($f);
  
}
}
?>

#2
CuteGuy

CuteGuy

    Active Member

  • Grup: Members
  • Posts: 1,870
  • Înscris: 11.09.2005
Poti bloca IP-urile fie direct din .htaccess, fie din cPanel (IP deny manager).

#3
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
si ce trebuie sa adaug la script pentru a baga un cod captha care sa trebuiasca introdus pentru a te lasa sa postezi? sau ceva in genul unei intrebari...si sa trebuiasca sa scrii raspunsul intr-o casuta pentru a te lasa sa postezi mesajul...stima

Edited by yo_suporter, 01 June 2012 - 14:01.


#4
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nu stie nimeni? :(

#5
OriginalCopy

OriginalCopy

    I'm harmful, fear me please! :))

  • Grup: Senior Members
  • Posts: 27,268
  • Înscris: 10.08.2006

View Postyo_suporter, on 1st June 2012, 13:44, said:

si ce trebuie sa adaug la script pentru a baga un cod captha care sa trebuiasca introdus pentru a te lasa sa postezi?
reCaptcha.

#6
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
am gasit pt captcha codul asta...
sursa :

<?php
    session_start();

    $_SESSION['captcha'] = mt_rand(100000, 999999);

    $image = imagecreate(128, 32);

    $bgcol = imagecolorallocate($image, 0xff, 0xff, 0xff);

    $txcol = imagecolorallocate($image, 0x00, 0x00, 0x00);

    $strn2 = imagestring($image, 2, 0, 0, $_SESSION['captcha'], $txcol);

    header("Content-type: image/png");

    imagepng($image);

    imagedestroy($image);
?>

si implementarea in pagina respectiva....

<img src='captcha.php' alt='captcha'>
<input type='text' name='captcha' size='6'>

da ce trebuie sa fac si cum il adaug la codul meu de guest book postat mai sus...ca atunci cand cineva vrea sa lase un mesaj...sa nul lase pana nu scrie corect acest cod captcha...stima

#7
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
si am mai gasit ceva asa...creare de 2 fisiere captcha.php si simple.php...

in captcha.php avem:

<?php
session_start();
//Cream imaginea
$im=imagecreatetruecolor(70, 20);
//Culoarea de fundal a imaginii
$bg=imagecolorallocate($im, 0, 0, 255);
imagefill($im, 0, 0, $bg);

//Culoarea la string
$text_color=imagecolorallocate($im, 255, 255, 255);
//O valoare aleatorie pe care trebuie sa o introduca userul
$rand=rand(10000, 50000);
imagestring($im, 5, 2, 2, $rand, $text_color);
//Specificam browser-ului ca este vorba de o imagine
header('Content-type:image/jpeg');
//Cream imaginea ca jpeg pentru a o vizualiza
imagejpeg($im);

//Cream o sesiune ce memoreaza valoarea din $rand
$_SESSION['check']=$rand;

?>


si in simple.php avem:


<?php session_start(); ?>
<form action="simple.php" method="POST">
<img src="captcha.php" alt=""/><br/>
<input type="text" name="check" required/>
<input type="submit" name="submit" value="Verifica"/>
</form>
<?php
if(isset($_POST['submit'])) {
    $check=$_POST['check'];
        //Verificam daca codul introdus de user este cel corect
    if($check==$_SESSION['check']) {
        echo "Cod introdus corect!";
        $status=TRUE;
    }
    else echo "Cod INCORECT!";
    if(isset($status)) {
        //Continua cu restul scriptul
    }
}

?>



dar cum adaptez acest captcha la scriptul meu guest book? ca atunci cand cineva lasa un mmesaj sa nu-l lase sa posteze pana nu scrie codul corect...? stima

#8
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nimeni nu ma poate ajuta?

#9
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
?

#10
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
chiar nu poate nimeni sa ma ajute? :( stima

#11
MarianG

MarianG

    be that as it may

  • Grup: Moderators
  • Posts: 31,451
  • Înscris: 10.08.2005
maestru OC a spus destul de clar

View PostOriginalCopy, on 2nd June 2012, 12:35, said:

reCaptcha.
http://www.google.com/recaptcha

#12
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
am implementat un script captcha...in guest book meu...dar nu stiu ce trebuie sa mai adaug ca atunci cand scrii un cod gresit sa nu te mai lase sa postezi...sa iti apara un mesaj de genl "cod captcha gresit"... acum daca nu introduci nici un cod, nu te lasa sa postezi...dar daca introduci orice cifra te lasa sa postezi...din ce cauza?  iata codul...va multumesc





<?php
class maxGuestbook{
   var $messageDir = 'messages';
   var $dateFormat = 'd-m-Y H:i';
   var $itemsPerPage = 10;
   var $messageList;
  
function processGuestbook(){
   if (isset($_POST['submit'])) {
      $this->insertMessage();
   }
   $page = isset($_GET['page']) ? $_GET['page'] : 1;
  
   $this->displayGuestbook($page);
}
  
function getMessageList(){

   $this->messageList = array();
  
// Open the actual directory
if ($handle = @opendir($this->messageDir)) {
// Read all file from the actual directory
while ($file = readdir($handle))  {
    if (!is_dir($file)) {
       $this->messageList[] = $file;
       }
}
}

rsort($this->messageList);

return $this->messageList;
}  

function displayGuestbook($page=1){
      $list = $this->getMessageList();
      //echo "<center><a href='add.php'>Leave a message</a></center>";
      echo "<table class='newsList'>";
      
      //Get start point and end point
      $startItem = ($page-1)*$this->itemsPerPage;
      if (($startItem + $this->itemsPerPage) > sizeof($list)) $endItem = sizeof($list);
      else $endItem = $startItem + $this->itemsPerPage;
      
      for ($i=$startItem;$i<$endItem;$i++){
         //foreach ($list as $value) {
         $value = $list[$i];
       $data = file($this->messageDir.DIRECTORY_SEPARATOR.$value);
       $name  = trim($data[0]);
       $email = trim($data[1]);
         $submitDate = trim($data[2]);
         $ip = trim($data[3]);
         unset ($data['0']);
         unset ($data['1']);
         unset ($data['2']);
         unset ($data['3']);
      
         $content = "";
         foreach ($data as $value) {
            $content .= $value;
         }
      
       echo "<tr><th align='left'><a href=\"mailto:$email\">$name</a></th>
                 <th class='right'>$submitDate</th></tr>";
       echo "<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>";
        echo "<tr><td colspan='2'>$ip<br/></td></tr>";
      }
      echo "</table>";
      if (sizeof($list) == 0){
         echo "<center><p>Nu exista mesaje in acest moment!</p><p>&nbsp;</p></center>";
      }
      // Create pagination
      if (sizeof($list) > $this->itemsPerPage){
         echo "<div id=\"navigation\">";
         if ($startItem == 0) {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Pagina urmatoare &raquo;</a></div>";
            } else {
               // Nothing to display
            }
         } else {
            if ($endItem < sizeof($list)){
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Pagina anterioara</a></div>";
               echo "<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Pagina urmatoare &raquo;</a></div>";
            } else {
               echo "<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Pagina anterioara</a></div>";
            }
         }
        
         echo "<br/></div><br/>";
      }
      echo "<hr />";
      $this->displayAddForm();
}

function displayAddForm(){
?>  
  <strong><form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Nume / E-mail:<br/>
    <input type="text" name="name" size="30"/><br/><br/>
    Mesajul tau:<br/>
    <textarea name="message" rows="7" cols="49"></textarea><br/></strong>

<?php session_start(); ?>
<form action="maxGuestbook.class.php" method="POST">
<img src="Imagini/captcha.php" alt=""/>
<input type="text" name="check" required/>
<input type="submit" name="submit" value="TRIMITE"/>
</form>
<?php
if(isset($_POST['submit'])) {
    $check=$_POST['check'];
        //Verificam daca codul introdus de user este cel corect
    if($check==$_SESSION['check']) {
        $status=TRUE;
    }
    if(isset($status)) {
        //Continua cu restul scriptul
    }
}

?>
  
<?php  
}

function insertMessage(){
   $name   = isset($_POST['name']) ? $_POST['name'] : 'Anonim';
   $email  = isset($_POST['email']) ? $_POST['email'] : '';
   $submitDate  = date($this->dateFormat);
   $content = isset($_POST['message']) ? $_POST['message'] : '';
  
  
   if (trim($name) == '') $name = 'Anonim';
   if (strlen($content)<5) {
      exit();
   }
  
   $filename = date('YmdHi');
   if (!file_exists($this->messageDir)){
      mkdir($this->messageDir);
   }
   $f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");        
   fwrite($f,$name."\n");
   fwrite($f,$email."\n");
   fwrite($f,$submitDate."\n");
   fwrite($f,"<span style=color:red>IP: ".$_SERVER['REMOTE_ADDR']."</span>\n");
   fwrite($f,$content."\n");
   fclose($f);
  
}
}
?>

#13
oauzor

oauzor

    Active Members

  • Grup: Senior Members
  • Posts: 5,409
  • Înscris: 25.10.2008
Te ajut eu contra-cost daca doresti. Bafta!

#14
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nu ma poate ajuta nimeni? :(

#15
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
nimeni nu imi poate da macar o indicatie?

#16
yo_suporter

yo_suporter

    Active Member

  • Grup: Members
  • Posts: 1,215
  • Înscris: 14.01.2010
???

#17
danutz0501

danutz0501

    Member

  • Grup: Members
  • Posts: 437
  • Înscris: 22.04.2008
Incearca sa adaugi un capcha matematic sau unul cu drag and drop, pt spam boti o sa fie mai greu. Ce trebuie sa adaugi e sesiuni php, scrii codul in sesiune din fisierul capcha, bagi foto in formular, campul de raspuns si compari ce primesti cu variabila din sesiune. Simplu nu?

Edited by danutz0501, 26 June 2012 - 19:42.


Anunturi

Chirurgia cranio-cerebrală minim invazivă Chirurgia cranio-cerebrală minim invazivă

Tehnicile minim invazive impun utilizarea unei tehnologii ultramoderne.

Endoscoapele operatorii de diverse tipuri, microscopul operator dedicat, neuronavigația, neuroelectrofiziologia, tehnicile avansate de anestezie, chirurgia cu pacientul treaz reprezintă armamentarium fără de care neurochirurgia prin "gaura cheii" nu ar fi posibilă. Folosind tehnicile de mai sus, tratăm un spectru larg de patologii cranio-cerebrale.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate