Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Blokada dodawania wpisu.
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


Witam. Szukam w google i nic nie mogę znaleźć.
Więc mój problem wygląda tak że mam sobie skrypt komentarzy [ oparty na plikach *.txt ] i ostatnio pojawili się SPAMERZY.
I mam takie pytanie jak zablokować (zbanować) IP ale tylko np na 5 min (IMG:style_emoticons/default/questionmark.gif)
Albo czego mam w google szukać(IMG:style_emoticons/default/questionmark.gif)
(IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Prześledź ten kod i zobacz, co zmieniłem (podświetlone wiersze)
[PHP] blokada.php - pobierz, plaintext
  1. <?php
  2. $pole1 = isset($_POST['pole1']) ? trim($_POST['pole1']) : '';
  3. $pole2 = isset($_POST['pole2']) ? trim($_POST['pole2']) : '';
  4.  
  5. if(file_exists("fip.txt")) $file = file("fip.txt");
  6. $time_5_min_ago = date("Y-m-d H:i:s", strtotime("-5 min"));
  7. // $rows = explode("\n", $file);
  8.  
  9.  
  10. if (empty($pole1) && empty($pole2)) {
  11.  
  12. // prosty formularz zawierający dwa pola
  13. echo '<form action="?dod" method="post">
  14. <input type="text" name="pole1" style="width: 200px;"/><br/>
  15. <textarea name="pole2" style="width: 200px; height: 100px;">
  16. </textarea><br/>
  17. <input type="submit" value="Zapisz" />
  18. </form>';
  19. } else
  20. if (isset($_GET['dod'])) {
  21.  
  22. if(isset($file)) { foreach ($file as $value)
  23. {
  24. $one_row = explode('`', $value);
  25. if ($one_row[0] == $_SERVER['REMOTE_ADDR'] && strtotime($one_row[1]) > strtotime($time_5_min_ago))
  26. {
  27. echo "Komentować można tylko raz na 5min.";
  28. }
  29. } }
  30. // } else {
  31. $dane = $_SERVER['REMOTE_ADDR']."`".date("Y-m-d H:i:s", time())."`".$pole1."`".$pole2."\n";
  32. $file = "fip.txt";
  33. $fp = fopen($file, "a");
  34. flock($fp, 2);
  35. fwrite($fp, $dane);
  36. flock($fp, 3);
  37. fclose($fp);
  38.  
  39. echo "Dane zostały zapisane!<br />";
  40. echo "<a href=\"index.php\">Zobacz wpisane dane</a>";
  41. }
  42. ?>
[PHP] blokada.php - pobierz, plaintext
Po co te zmiany?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 03:08