Setting up captcha with a conditional

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vinn1e
Forum Newbie
Posts: 1
Joined: Wed Nov 11, 2009 8:02 pm

Setting up captcha with a conditional

Post by Vinn1e »

hey guys im new to codding and am in deep , lol want to insert a captcha in my script but alternate it appearing based upon a random number.

Please if any one can tell me where im going wrong. cheers

Code: Select all

 
 
 
<center>
<?
$random_number = rand(1,10);
if ( $random_number <= 7 )}
 {else} 
require_once('recaptchalib.php');
$publickey = "*****"; // you got this from the signup page
echo recaptcha_get_html($publickey);
{
?>
</center>

this is the bit that came wit recaptcha and loads the process , above that was my first attempt at a conditional.

Code: Select all

require_once('recaptchalib.php');
$publickey = "*****"; // you got this from the signup page
echo recaptcha_get_html($publickey);
{
any help getting this working would be huge.

Thanks in advance
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: Setting up captcha with a conditional

Post by akuji36 »

Hello

Take a look at this:

http://www.finalwebsites.com/snippets.php?id=39

thanks

Rod

:)
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: Setting up captcha with a conditional

Post by timWebUK »

Was this what you were trying to achieve?

Code: Select all

 <?php
 
    $random_number = rand(1,10);
    if ( $random_number < 8 )
    {
        require_once('recaptchalib.php');
        $publickey = "*****"; // you got this from the signup page
        echo recaptcha_get_html($publickey);
    }
    else
    {
    //Additional Code Here
    }
    
?> 
Although this would work, when you sent the form to the PHP processing file, you would still have the reCAPTCHA private key there... so this wouldn't work.

Why do you want it to randomly appear?
Post Reply