Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP Captcha code editing

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP Captcha code editing

Postby pomuc » Fri Oct 12, 2012 2:43 am

Hello everybody.
I really need your help. I am not good at all at PHP programming, I am working with AS3, and only necessary to make a PHP Captcha in my Flash module.
So I have found a template of captcha, with contains 2 fils .php. 1-st is code generation, 2nd is form. So here is 2nd
Code: Select all
<?php
session_start();

if( isset($_POST['submit'])) {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
      $correctAnswer =  "Thank you. Your message said "'.$_POST['message'].';
      echo $correctAnswer;
      unset($_SESSION['security_code']);
   } else {
      // Insert your code for showing an error message here
      $wrongAnswer = "Wrong code, try again please";
      echo $wrongAnswer;
   }
} else {}
?>


So I need help to fix some things:
1) How can I activate script to validation checking without pushing submit button in that PHP form (isset($_POST['submit'])) I need it to be activated after Flash gave a value to $security_code and sent it t PHP.
2) in case if user wrote wrong code, script just open an error message in new window, how to make it jsut reload a captcha image?

Thanks, hoping on your help :help:
pomuc
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Oct 12, 2012 2:19 am

Re: PHP Captcha code editing

Postby seandisanti » Fri Oct 12, 2012 9:04 am

the easiest way to get exactly what you want is to do it yourself. Assuming you are better at actionscript than php, you can use php.net/function_name to research the functions listed in your php code that aren't immediately obvious (or we can help also) and the recreate the functionality in your actionscript. I know that sounds like more work, and i guess it is more work than having someone just make what you've found work but you will like the result a lot more if you go that route.

ok, that said, the script that you've posted is handling post data from a form submission. you can use DOM interaction to submit a form without a click, but you're still going to need to submit as a form in order to access POST variables. you could do it with get variables (passing values to the page via viewable url changes), but it would completely defeat the purpose and just be a waste of time.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: PHP Captcha code editing

Postby pomuc » Sat Oct 13, 2012 5:49 am

the funniest thing is that mistake was sooo visible, but for me, who didnt know PHP at all that took 3 days to find it. :(
Code: Select all
<?php
session_start();
$security_code = $_POST['security_code'];
$sub = $_POST['sub'];
if ($_POST['sub'] == "parse") {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
        // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
        print "return_msg=correct";
        unset($_SESSION['security_code']);
   } else {
        // Insert your code for showing an error message here
        print "return_msg=wrong";
       
   }
}
?>

So now it is working, but i still need to "reload" script on wrong captcha CODE entering. Could somebody help me with thaT please? :help:
pomuc
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Oct 12, 2012 2:19 am

Re: PHP Captcha code editing

Postby seandisanti » Mon Oct 15, 2012 7:42 am

a function I always include in my functions.php file for any project is redirect_to(). I picked it up from a lynda.com video and it just stuck.

Code: Select all
function redirect_to( $location = NULL ) {
   if ($location != NULL) {
      header("Location: {$location}");
      exit;
      }
   }

you can of course use the header() to redirect without the wrapper, but this way just resonates a little better with me somehow. anyway, on wrong submission, just redirect_to the same page.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.