Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jquery][captcha] sexy captcha - problem ze zmiennymi w sesji
blasq
post 22.09.2011, 19:30:48
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.11.2010

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


Witam

pracuję nad prostym systemem komentarzy. Zastosowałem sexy captcha, zgodnie z opisem na stronie: http://blog.lukeblackamore.com/2009/10/sex...op-captcha.html

moja stronka: http://trzezwymokiem.ovh.org/drudle/comment.php

Mechanizm działa, ale połowicznie. Tzn rzeczywiście jeśli zostanie wskazany zły element to dodanie komentarza nie zadziała, jednak jeśli nie zostanie wskazany żadny element, dodanie przechodzi gładko. Błąd jest jak przypuszczam gdzieś w zmiennych w sesji. Oto kody


comment.php:
  1. <?php session_start(); ?>
  2. <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-2" />
  3.  
  4.  
  5.  
  6. <link rel="stylesheet" href="styl.css" type="text/css">
  7. <script type="text/javascript" src="jquery.js"></script>
  8.  
  9. <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
  10. <script type="text/javascript" src="js/jquery.sexy-captcha-0.1.js"></script>
  11. <link rel="stylesheet" type="text/css" media="all" href="css/sexy-captcha/styles.css" />
  12.  
  13.  
  14. <script type="text/javascript" >
  15.  
  16.  
  17. $(function() {
  18. $(".submit").click(function()
  19. {
  20.  
  21.  
  22.  
  23. var name = $("#name").val();
  24. var comment = $("#comment").val();
  25. var dataString = 'name='+ name + '&comment=' + comment;
  26. if(name=='' || comment=='')
  27. {
  28. alert('Wpisz nick oraz treść komentarza');
  29. }
  30. else
  31. {
  32. $("#flash").show();
  33. $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
  34.  
  35. $.ajax({
  36. type: "POST",
  37. url: "commentajax.php",
  38. data: dataString,
  39. cache: false,
  40. success: function(html){
  41. $("ol#update").append(html);
  42. $("ol#update li:last").fadeIn("slow");
  43. $("#flash").hide();
  44. }
  45. });
  46. }return false;
  47.  
  48.  
  49.  
  50.  
  51. });
  52. });
  53.  
  54. $(document).ready(function() {
  55. $('.myCaptcha').sexyCaptcha('captcha.process.php');
  56.  
  57.  
  58. });
  59.  
  60.  
  61.  
  62.  
  63. </head>
  64.  
  65.  
  66. <div id="all"> <br />
  67. <div id="osiemset"> <br /><br />
  68. <div id="srodek">
  69.  
  70.  
  71. <br /><br />
  72.  
  73. <br /><br />
  74.  
  75. <div>
  76. <form action="#" method="post" id="formularz">
  77. <input type="text" id="name" placeholder="imie"/><br /><br />
  78. <textarea id="comment" cols="60" rows="3"></textarea><br />
  79. <br /><br />
  80. Chcemy upewnić się, że jesteś człowiekiem, przeciągnij odpowiedni element na prawo:<br /><br />
  81. <div class="myCaptcha"> </div><br />
  82.  
  83. <input type="submit" class="submit" value=" Submit Comment " id="submit" /> </form>
  84. <div id="flash"></div>
  85.  
  86. <ol id="update" class="timeline">
  87. </ol>
  88.  
  89.  
  90.  
  91. </div>
  92. <br /><br /><br /><br /><br /><br /><br />
  93. </div><br /><br />
  94. </div>
  95.  
  96.  
  97.  
  98. </body>
  99. </html>




commentajax.php:
  1. <?php
  2. header('Content-Type: text/html; charset=ISO-8859-2');
  3. function znaki_pl($string)
  4. {
  5. $przed= array('%u0105','%u0107','%u0119','%u0142','%u0144','%F3','%u015B','%u017A','%u017C',
  6. '%u0104','%u0106','%u0118','%u0141','%u0143','%D3','%u015A','%u0179','%u017B');
  7. $po= array("ą","ć","ę","ł","ń","ó","ś","ź","ż",
  8. "Ą","Ć","Ę","Ł","Ń","Ó","Ś","Ź","Ż");
  9.  
  10. $string = str_replace($przed, $po, $string);
  11. return $string;
  12. }
  13.  
  14.  
  15.  
  16. session_start();
  17.  
  18. $requestVars = isset($_REQUEST) ? $_REQUEST : array();
  19. echo $_SESSION['captchaCodes'][$_SESSION['captchaAnswer']];
  20. if (substr($requestVars['captcha'], 10) != $_SESSION['captchaCodes'][$_SESSION['captchaAnswer']]) {
  21.  
  22.  
  23. if($_POST)
  24. {
  25.  
  26.  
  27. $name=$_POST['name'];
  28. $email=$_POST['email'];
  29. $comment=$_POST['comment'];
  30. $lowercase = strtolower($email);
  31. $image = md5( $lowercase );
  32. require('ustawienia.php');
  33. connection();
  34. $q="INSERT into drudle_comment (name, comment, drudle_id) values ('$name', '$comment', '1')";
  35. mysql_query($q);
  36.  
  37. }
  38. else { }
  39.  
  40. ?>
  41. <li class="box">
  42. <br />
  43. <?php echo $name;?><br /><br />
  44. <?php echo $comment; ?>
  45. </li> <?
  46.  
  47. }
  48.  
  49. else {
  50.  
  51. echo znaki_pl("<div class=\"alert\">Nie przeszedłeś pozytywnie testu antyspamowego! <br />Użyj przycisku refresh i spróbuj jeszcze raz.</div>");
  52. }
  53. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:07