Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z formularzem i captcha
Forum PHP.pl > Forum > Po stronie przeglądarki
MatexQ
Witam. Mam problem z następującym kodem:

  1. <?php
  2.  
  3. function mailing() {
  4. echo "<div id='mailing'>";
  5. $imie = $_POST['imie'];
  6. $email = $_POST['mail'];
  7. $telefon = $_POST['telefon'];
  8. $temat = $_POST['temat'];
  9. $wiadomosc = $_POST['wiadomosc'];
  10. $captcha = $_POST['captcha'];
  11.  
  12.  
  13.  
  14. $message = "<p>Imię i nazwisko: ".$imie."</p> <br>".
  15. "<p>Adres e-mail: ".$email."</p>".
  16. "<p>Temat wiadomości: ".$temat."</p>".
  17. "<p>Treść wiadomości: ".$wiadomosc."</p>";
  18.  
  19. $headers = "From: $email \n";
  20. $headers .= "MINE-Version: 1.0\n";
  21. $headers .= "Contact-Type: text/html; charset=UTF-8\n";
  22. mail('xxx@gmail.com',$temat, $message, $headers);
  23.  
  24.  
  25.  
  26. $widok = "<div id='podziekowanie'>Wiadomość została wysłana!<br> Dziękujemy. Postaramy się odpowiedzieć najszybciej, jak to tylko możliwe.
  27. <br><br> Za 5 sekund nastąpi przekierowanie na stronę główną. Prosimy czekać.
  28.  
  29. </div>" ;
  30. return $widok;
  31.  
  32.  
  33.  
  34. };
  35.  
  36. function form($pola=false) {
  37.  
  38. return $form = '<div id="formularz">
  39.  
  40. <form method="post" action="kontakt.php">
  41. <div>
  42.  
  43. <label for = "imie">Imię i nazwisko * </label>
  44. <input type="text" value = "'.$pola['imie'].'" name="imie" required placeholder="Wpisz imię i nazwisko">
  45. </div>
  46.  
  47. <br />
  48.  
  49. <div>
  50. <label for = "mail">Adres e-mail *</label>
  51. <input type="text" value = "'.$pola['mail'].'" name="mail" required placeholder="Twój Adres E-Mail"> <br>
  52. </div>
  53.  
  54. <br />
  55.  
  56. <div>
  57. <label for = "telefon">Telefon *</label>
  58. <input type="text" value = "'.$pola['telefon'].'" name="telefon" required placeholder="Podaj swój numer telefonu"> <br>
  59. </div>
  60.  
  61. <br />
  62.  
  63. <div>
  64. <label for = "temat">Temat *</label>
  65. <input type="text" value = "'.$pola['temat'].'" name="temat" required placeholder="Nazwa Tematu"><br>
  66. </div>
  67.  
  68. <br />
  69.  
  70. <div>
  71. <label for = "wiadomosc">Zapytanie *</label>
  72. <textarea name="wiadomosc" required placeholder="Wiadomość...">'.$pola['wiadomosc'].' </textarea> <br>
  73. </div>
  74.  
  75. <br /><br />
  76.  
  77. <div id="captcha">
  78. <label for = "wiadomosc">Captcha *</label>
  79. <img src="image.php"> <br>
  80. <input type="text" value = "'.$pola['captcha'].'" name="captcha" required placeholder="Przepisz kod z obrazka..."><br>
  81. </div>
  82.  
  83. <br />
  84.  
  85. <div>
  86. <br>
  87. <input type="reset" value="Wyczyść">
  88. <input type="submit" value="Wyślij">
  89.  
  90. </div>
  91.  
  92. </form>
  93. </div>';
  94. }
  95.  
  96.  
  97.  
  98. if ($_POST){
  99. $image = $_POST['image'];
  100. if(empty($_POST['imie'])) {
  101. echo "<br><h2><center>Podaj imię i nazwisko!</center></h2><hr>";
  102. echo form($_POST);
  103. }
  104.  
  105.  
  106. else if(empty($_POST['mail'])) {
  107. echo "<br><h2><center>Podaj adres e-mail!</center></h2><hr>";
  108. echo form($_POST);
  109. }
  110.  
  111. else if(empty($_POST['temat'])) {
  112. echo "<br><h2><center>Podaj temat zapytania!</center></h2><hr>";
  113. echo form($_POST);
  114. }
  115.  
  116. else if(empty($_POST['wiadomosc'])) {
  117. echo "<br><h2><center>Podaj treść zapytania!</center></h2><hr>";
  118. echo form($_POST);
  119. }
  120.  
  121. else if(isset($_POST['telefon']) AND !is_numeric($_POST['telefon'])) {
  122. echo "<br><h2><center>Podany numer telefonu jest nieprawidłowy!</center></h2><hr>";
  123. echo form($_POST);
  124. }
  125.  
  126.  
  127. else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9]+)*@[a-z0-9]+(\.[a-z0-9]+)*(\.[a-z]{2,4})$", $_POST['mail'])) {
  128. echo "<br><h2><center>Wprowadzony adres e-mail jest niepoprawny!</center></h2><hr>";
  129. echo form($_POST);
  130. }
  131.  
  132. else if(empty($_POST['captcha'])) {
  133. echo "<br><h2><center>Proszę podać kod!</center></h2><hr>";
  134. echo form($_POST);
  135. }
  136.  
  137. else if($_POST['captcha'] != $image) {
  138. echo "<br><h2><center>Proszę podać poprawny kod!</center></h2><hr>";
  139. echo form($_POST);
  140. }
  141.  
  142. else if($image == $_SESSION['string']) {
  143.  
  144. echo form();
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. else { echo mailing();}
  155. } else {echo form();};
  156.  
  157.  
  158.  
  159. ?>



Problem polega na tym, że kod wysyła formularz zawsze pomimo złego kodu captcha. Próbowałem na kilka sposobów i nic mi nie wychodzi. Podsyłam jeszcze plik image.php

  1. <?php
  2.  
  3. $img = imagecreatetruecolor(150,40);
  4.  
  5. $white = imagecolorallocate($img, 255, 255, 255);
  6. $black = imagecolorallocate($img, 0, 0, 0);
  7. $grey = imagecolorallocate($img,150,150,150);
  8. $red = imagecolorallocate($img, 255, 0, 0);
  9. $pink = imagecolorallocate($img, 200, 0, 150);
  10.  
  11. function randomString($length){
  12. $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  13. srand((double)microtime()*1000000);
  14. $str = "";
  15. $i = 0;
  16.  
  17. while($i <= $length){
  18. $num = rand() % 33;
  19. $tmp = substr($chars, $num, 1);
  20. $str = $str . $tmp;
  21. $i++;
  22. }
  23. return $str;
  24. }
  25.  
  26. for($i=1;$i<=rand(1,5);$i++){
  27. $color = (rand(1,2) == 1) ? $pink : $red;
  28. imageline($img,rand(5,70),rand(5,20), rand(5,70)+5,rand(5,20)+5, $color);
  29. }
  30.  
  31. imagefill($img, 0, 0, $white);
  32.  
  33. $string = randomString(rand(7,10));
  34. $_SESSION['string'] = $string;
  35.  
  36. imagettftext($img, 18, 0, 10, 20, $black, "Arial.ttf", $string);
  37.  
  38. header("Content-type: image/png");
  39. imagepng($img);
  40. imagedestroy($img);
  41. ?>
trueblue
  1. $image = $_POST['image'];

Skąd jest powyższa zmienna?

A co z tym idzie:
  1. else if($_POST['captcha'] != $image) {
  2. else if($image == $_SESSION['string']) {


P.S. Nie uważasz, że czcionka jest zbyt duża?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.