This topic is locked

Captcha without flash

8/1/2014 4:34:18 PM
PHPRunner Tips and Tricks
F
FunkDaddy author

Needless to say we have too many iOS devices accessing our apps nowadays... unfortunately, the built-in captcha control provided by PHPR uses flash. Here is a solution to implementing captcha that does not use flash. I borrowed partial code from this post:http://webdesignpub.com/html-contact-form-captcha/
First:

Download php script file from here: http://webdesignpub.com/files/contact-form/html-contact-form-captcha.zip
Second:

Find a place in your PHPR form where you want to add the captcha image and insert a php snippet.


$random_value = rand();
echo '

<div>

<img src="captcha_code_file.php?rand='.$random_value.'" id="captchaimg" >
<label for="message">Enter the code above here :</label>
<input id="value_CaptchaValue_1" style="" type="text" name="value_CaptchaValue_1" value="">
<small>Can\'t read the image? click <a href="javascript: refreshCaptcha();">here</a> to refresh</small>
</div>
<script type="text/javascript">

function refreshCaptcha(){

//console.log("captcha refresehed");

var img = document.images["captchaimg"];

img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;

}

</script>';


Third:

Copy and paste the file your downloaded from zip folder in first step called "captcha_code_file.php" and place it in your project directory (root folder of project... not necessarily your web server root). Also copy the monofont.ttf file to same location.
Fourth:

In your PHPR form "Before record Added" or "Before record updated" event (depends if you are using it on a add or edit type form) add the following code:



if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $values['CaptchaValue']) != 0){

//Note: the captcha code is compared case insensitively.

//if you want case sensitive match, update the check above to strcmp()
$message = "<div style='background-color: #FF0; padding-top: 10px; padding-bottom: 10px;color: #F00;font-size: 1.2em;'>

The captcha code below does not match! Try again.

</div>";

return false;

}


Notice that I am using a PHPR field that I created in my underlying table called "CaptchaValue" which is why I included the $values['CaptchaValue'] in the conditional statement above. This is what captures the user input to verify if they entered the same thing that is presented in the captcha image.
Fifth:

In the same form go to the "After record added" or "After record updated" event and add the following code to unset the $_SESSION['6_letter_code'] var to prevent same captcha value entered by user from being used again.



unset($_SESSION['6_letters_code']);//Unset this after submission so it needs to be recreated and cannot be reused by hackers


Done!
That's it. You can also tweak some values in the "captcha_code_file.php" to change the size of the image and a few other things.
Hope this helps folks out there and maybe even makes it into a new version of PHPR given the Flash issues with iOS devices).

romaldus 8/14/2014

Not Work in PHPRUNNER 6.2.

Captcha always show warning : "The captcha code below does not match! Try again. " even if i enter correct code

A
Abbas 10/24/2014

Notice that I am using a PHPR field that I created in my underlying table called "CaptchaValue" which is why I included the $values['CaptchaValue'] in the conditional statement above. This is what captures the user input to verify if they entered the same thing that is presented in the captcha image.


I hope to clarify this point
Regards

Abbas

F
FunkDaddy author 10/28/2014

Abbas,
What I meant by the paragraph you highlighted is that I added a varchar(6) field/column called "CaptchaValue" in the MySQL table that I was using to capture my user info (which is where I placed the captcha widget to help validate the form). I did this so that it could be used for capturing the value for the captcha that is entered by the user... hence I can access that value by calling the array item $values['CaptchaValue'] in order to compare it to the $_SESSION['6_letters_code']. I hope this clarifies things.

A
Abbas 10/30/2014



Abbas,
What I meant by the paragraph you highlighted is that I added a varchar(6) field/column called "CaptchaValue" in the MySQL table that I was using to capture my user info (which is where I placed the captcha widget to help validate the form). I did this so that it could be used for capturing the value for the captcha that is entered by the user... hence I can access that value by calling the array item $values['CaptchaValue'] in order to compare it to the $_SESSION['6_letters_code']. I hope this clarifies things.


Thank you for your replay <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=76114&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

A
Abbas 12/18/2014

Sir,
Did you try it in the log-in page?
It is always showing message: "The captcha code below does not match! Try again. "
I've changed

$values['CaptchaValue']



to

$_POST['value_CaptchaValue_1']


if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['value_CaptchaValue_1']) != 0){

//Note: the captcha code is compared case insensitively.

//if you want case sensitive match, update the check above to strcmp()
$message = "<div style='background-color: #FF0; padding-top: 10px; padding-bottom: 10px;color: #F00;font-size: 1.2em;'>

The captcha code below does not match! Try again.

</div>";

return false;

}


I think the reason it is not saved the session 6_letters_code

romaldus 12/19/2014

I have never had success using this tips in phprunner 7.1 and 8.0 latest version.

Warning message"The captcha code below does not match! Try again. " always appears even if i enter correct captcha challenge.
sample table:
field1(integer, primary key)

field2 (char 30)

field3 (char 30)

CaptchaValue (char 10)

lefty 6/8/2016



I have never had success using this tips in phprunner 7.1 and 8.0 latest version.

Warning message"The captcha code below does not match! Try again. " always appears even if i enter correct captcha challenge.
sample table:
field1(integer, primary key)

field2 (char 30)

field3 (char 30)

CaptchaValue (char 10)



Anybody have success with this? Works great for desktop but afraid to try above code based on responses. FunkDaddy any input on this or are we going about it the wrong way?

lefty 6/8/2016



I have never had success using this tips in phprunner 7.1 and 8.0 latest version.

Warning message"The captcha code below does not match! Try again. " always appears even if i enter correct captcha challenge.
sample table:
field1(integer, primary key)

field2 (char 30)

field3 (char 30)

CaptchaValue (char 10)



Anybody have success with this? Works great for desktop but afraid to try above code based on responses. FunkDaddy any input on this or are we going about it the wrong way? Using 8.0 phprunner.

admin 6/8/2016

Switch to 8.1 and use built-in re-CAPTCHA?