Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Walidacja Captcha
Ajjlechu
post 2.01.2021, 16:14:11
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 2.01.2021

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


Witam,

Jestem nowy na Forum oraz potrzebuje waszej pomocy bo nie moge sobie poradzic z Captcha.

Problem jest tylko jeden ale dla mnie trudny, wszystko dziala jak nalezy ale jak ktos przepisze niepoprawnie captche to i tak wiadomosc zostaje wyslana...

Nie moge sobie poradzic zeby to razem zgrac z php

mam nadzieje ze ktos bylby tak mily i pomoglby mi albo podpowiedzial jak ta linijke w php dostosowac aby to dzialalo..


czyli najlatwiej mowiac jak moge tutdaj dodac linijke ktora wywali blad ze captcha zostala zle przepisana

  1. $json=array("status"=>1,"msg"=>"<p class='status_ok'>Your message has been sent correctly.<br>Within a few seconds you will receive a copy of the sent E-Mail.<br>Thank you very much for using the service from<br>blabla</p>");
  2. }
  3. }
  4. else{
  5. $json=array("status"=>0,"msg"=>"<p class='status_err'>A script error has occurred.<br>Don`t worry, it's okay :)<br>Please try to send the same message again.</p>");
  6. }
  7. }
  8. else{
  9. $json=array("status"=>0,"msg"=>"<p class='status_err'>Please complete the required<br>fields marked with an asterisk *<br>and try to send the message again.</p>");
  10. }
  11. echo json_encode($json);
  12. ?>



Ponizej przesylam caly kod

ENkontaktmail.php

  1. <?php
  2. header("content-type: application/json; charset=UTF-8");
  3. $fname=isset($_POST['fname']) ? $_POST['fname'] : "";
  4. $sname=isset($_POST['sname']) ? $_POST['sname'] : "";
  5. $email=isset($_POST['email']) ? $_POST['email'] : "";
  6. $phone=isset($_POST['phone']) ? $_POST['phone'] : "";
  7. $titel=isset($_POST['titel']) ? $_POST['titel'] : "";
  8. $CaptchaInput=isset($_POST['CaptchaInput']) ? $_POST['CaptchaInput'] : "";
  9. $datenschutz=isset($_POST['datenschutz']) ? $_POST['datenschutz'] : "";
  10. $message=isset($_POST['message']) ? $_POST['message'] : "";
  11. if($fname && $email && $sname && $titel && $message && $CaptchaInput && $datenschutz){
  12. $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit";
  13. $message_body = '
  14. <!DOCTYPE html>
  15.  
  16. </html>
  17. ';
  18. $message_body1 = '
  19. <!DOCTYPE html>
  20.  
  21. </html>
  22. ';
  23. if(mail("sara@blabla.ch","$titel",$message_body,$headers,"-f sara@blabla.ch")){
  24. if(mail("$email","$titel",$message_body1,$headers,"-f sara@blabla.ch")){
  25. $json=array("status"=>1,"msg"=>"<p class='status_ok'>Your message has been sent correctly.<br>Within a few seconds you will receive a copy of the sent E-Mail.<br>Thank you very much for using the service from<br>blabla</p>");
  26. }
  27. }
  28.  
  29.  
  30.  
  31. else{
  32. $json=array("status"=>0,"msg"=>"<p class='status_err'>A script error has occurred.<br>Don`t worry, it's okay :)<br>Please try to send the same message again.</p>");
  33. }
  34. }
  35. else{
  36. $json=array("status"=>0,"msg"=>"<p class='status_err'>Please complete the required<br>fields marked with an asterisk *<br>and try to send the message again.</p>");
  37. }
  38. echo json_encode($json);
  39. ?>


contact.html

  1. <div class="site-section bg-light text-black">
  2. <div class="container">
  3. <div class="row">
  4. <div class="col-md-7 mb-5">
  5. <form method="post" action="../../php/ENkontaktmail.php" id="contact_form" onsubmit="return checkform(this);" class="p-5 bg-white">
  6. <h2 class="text-center display-3">Contact form</h2>
  7. <div class="row form-group">
  8. <div class="row form-group">
  9. <div class="col-md-12">
  10. <div class="text-center" id="CaptchaDiv"></div>
  11. <input type="hidden" id="txtCaptcha">
  12. <div class="text-center"><label for="CaptchaInput">Please enter the five-digit security code*</label>
  13. <input type="text" minlength=5 maxlength=5 name="CaptchaInput" id="CaptchaInput" required="required" placeholder="Security code" class="form-control text-center"></div>
  14. </div>
  15. </div>
  16. <div class="row text-center form-group">
  17. <div class="col-md-12">
  18. <input type="submit" value="Send" class="btn btn-black py-3 px-5">
  19. <div class="text-center text-primary" id="send_form_status"></div>
  20. </div>
  21. </div>
  22. </form>
  23. </div>
  24. </div>
  25. </div>



generator captcha .js

  1. function ValidCaptcha(){
  2. [b]var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
  3. var str2 = removeSpaces(document.getElementById('CaptchaInput').value);[/b]
  4. if (str1 == str2){
  5. return true;
  6. }else{
  7. return false;
  8. }
  9. }
  10. function removeSpaces(string){
  11. return string.split(' ').join('');
  12. }
  13. var a = Math.ceil(Math.random() * 9)+ '';
  14. var b = Math.ceil(Math.random() * 9)+ '';
  15. var c = Math.ceil(Math.random() * 9)+ '';
  16. var d = Math.ceil(Math.random() * 9)+ '';
  17. var e = Math.ceil(Math.random() * 9)+ '';
  18. var code = a + b + c + d + e;
  19. document.getElementById("txtCaptcha").value = code;
  20. document.getElementById("CaptchaDiv").innerHTML = code;



tak to wyglada



Ten post edytował Ajjlechu 2.01.2021, 16:28:27
Go to the top of the page
+Quote Post
shpaque
post 14.01.2021, 15:51:31
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


po co bawic sie z captcha, nie lepiej z reCaptcha..?

jesli chcesz zeby uruchomic jakakolwiek komende php po uruchomieniu js... to tylko tworzac oddzielny plik php do wykonania go ajaxem poprzez json
Go to the top of the page
+Quote Post
Ajjlechu
post 29.01.2021, 08:09:00
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 2.01.2021

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


Dziekuje koledze powyzej i prosilbym o mala podpowiedz bo nie moge sobie rowniez poradzic i z tym skryptem od googli, php nie jest moja mocna strona

wiec najpierw pokaze co posiadam

a posiadam formularz kontaktowy w html

contact.html

  1. <form method="post" action="../../php/ENkontaktmail.php" id="contact_form" class="p-5 bg-white">
  2. <h2 class="text-center display-3">Contact form</h2>
  3. <div class="row form-group">
  4. <div class="col-md-6 mb-3">
  5. <div class="text-center"><label for="fname">First Name*</label>
  6. <input type="text" minlength=2 maxlength=30 name="fname" id="fname" required="required" placeholder="Your first name" class="form-control text-center"></div>
  7. </div>
  8. <div class="col-md-6 mb-3">
  9. <div class="text-center"><label for="sname">Last Name*</label>
  10. <input type="text" minlength=2 maxlength=30 name="sname" id="sname" required="required" placeholder="Your last name" class="form-control text-center"></div>
  11. </div>
  12. <div class="col-md-12">
  13. <div class="text-center"><label for="phone">Phone number</label>
  14. <input type="text" maxlength=15 name="phone" id="phone" placeholder="Your phone number" class="form-control text-center"></div>
  15. </div>
  16. <div class="col-md-12">
  17. <div class="text-center"><label for="email">E-Mail*</label>
  18. <input type="email" minlength=5 maxlength=30 name="email" id="email" required="required" placeholder="Your E-Mail address" class="form-control text-center"></div>
  19. </div>
  20. <div class="col-md-12 mb-3 mb-md-0">
  21. <div class="text-center"><label for="titel">Title*</label>
  22. <input type="text" minlength=2 maxlength=30 name="titel" id="titel" required="required" placeholder="Subject" class="form-control text-center"></div>
  23. </div>
  24. </div>
  25. <div class="row form-group">
  26. <div class="col-md-12">
  27. <div class="text-center"><label for="message">Message*</label>
  28. <textarea name="message" minlength=5 maxlength=500 id="message" cols="30" rows="7" required="required" placeholder="What would you like to ask?" class="form-control text-center"></textarea></div></div>
  29. </div>
  30. <div class="row form-group">
  31. <div class="col-md-12">
  32. <div class="text-center"><div class="g-recaptcha d-inline-block" data-theme="dark" data-sitekey="moj klucz">
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="col-md-12 mb-3 mb-md-0 regeln">
  38. <div class="text-center"><label for="datenschutz">Privacy policy*</label><br></div>
  39. <p><input type="checkbox" name="datenschutz" id="datenschutz" required="required">&nbsp;&nbsp;&nbsp;By submitting the form, you agree that your data will be used to process your request.<br>(You can find further information and cancellation notices in the <a href="privacypolicy&publisher.html"><b>Privacy policy</b></a>).</p>
  40. </div>
  41. <br>
  42. <div class="row text-center form-group">
  43. <div class="col-md-12">
  44. <input type="submit" value="Send" class="btn btn-black py-3 px-5">
  45. <div class="text-center text-primary" id="send_form_status"></div>
  46. </div>
  47. </div>
  48. </form>


ponizej posiadam jave ktora wykonuje uruchomienie php

  1. $(document).ready(function() {
  2. $("html").on("submit","#contact_form",function(e){
  3. $('#kontakthintergrund').show();
  4. e.preventDefault();
  5. $("#send_form_status").html('').hide();
  6. var data=$("#contact_form").serialize();
  7. $.post("../php/ENkontaktmail.php",data,function(res){
  8. $("#send_form_status").html(res.msg).show();
  9. $('#kontakthintergrund').fadeOut(1500);
  10. if(res.status==1){
  11. $("#contact_form")[0].reset();
  12. }
  13. });
  14. });
  15. });


i na samym koncu php

  1. <?php
  2.  
  3. if(isset($_POST['g-recaptcha-response'])){
  4. $captcha=$_POST['g-recaptcha-response'];
  5. }
  6. if(!$captcha){
  7. echo '<h2>Please check the the captcha form.</h2>';
  8. }
  9.  
  10.  
  11. header("content-type: application/json; charset=UTF-8");
  12. $fname=isset($_POST['fname']) ? $_POST['fname'] : "";
  13. $sname=isset($_POST['sname']) ? $_POST['sname'] : "";
  14. $email=isset($_POST['email']) ? $_POST['email'] : "";
  15. $phone=isset($_POST['phone']) ? $_POST['phone'] : "";
  16. $titel=isset($_POST['titel']) ? $_POST['titel'] : "";
  17. $datenschutz=isset($_POST['datenschutz']) ? $_POST['datenschutz'] : "";
  18. $message=isset($_POST['message']) ? $_POST['message'] : "";
  19.  
  20.  
  21. if($fname && $email && $sname && $titel && $message && $datenschutz){
  22. $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit";
  23. $message_body = '
  24. <!DOCTYPE html>
  25.  
  26. </html>
  27. ';
  28. $message_body1 = '
  29. <!DOCTYPE html>
  30.  
  31. </html>
  32. ';
  33. if(mail("sara@l.c","$titel",$message_body,$headers,"-f sara@.c")){
  34. if(mail("$email","$titel",$message_body1,$headers,"-f sara@.")){
  35. $json=array("status"=>1,"msg"=>"<p class='status_ok'>Your message has been sent correctly.<br>Within a few seconds you will receive a copy of the sent E-Mail.<br>Thank you very much for using the service from<br>L.</p>");
  36. }
  37. }
  38. else{
  39. $json=array("status"=>0,"msg"=>"<p class='status_err'>A script error has occurred.<br>Don`t worry, it's okay :)<br>Please try to send the same message again.</p>");
  40. }
  41. }
  42. else{
  43. $json=array("status"=>0,"msg"=>"<p class='status_err'>Please complete the required<br>fields marked with an asterisk *<br>and try to send the message again.</p>");
  44. }
  45. echo json_encode($json);
  46.  
  47.  
  48.  
  49.  
  50. ?>




sam skryp dziala super, jest dla mnie w miare zrozumialy dlatego dalej na nim robie

Co mnie najbardziej boli to ze nie jestem w stanie dodac Captchi od google do PHP, udalo mi sie dodac pierwsze linijki ktore dzialaja ale juz nie moge dodac mojego sekretnego klucza...

Czy bylby ktos z was mili forumowicze sprawdzic co jest zle lub cos podpowiedziec?





Go to the top of the page
+Quote Post

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: 28.03.2024 - 18:52