function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bujjibujji 

Php code implementation

Hi Guys,

 

I have a piece of code in php to implement Captcha, but exactly i don't know how to implement this one visualforce and apex.. If anybody knows how to do it please explain how to implement.

 

Below is the code of php..

 

 <?php session_start(); ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Author" content="Jose Rodriguez" />
<title>Captcha test</title>
<style type="text/css">
body { font-family: sans-serif; font-size: 0.8em; padding: 20px; }
#result { border: 1px solid green; width: 300px; margin: 0 0 35px 0; padding: 10px 20px; font-weight: bold; }
#change-image { font-size: 0.8em; }
</style>
</head>
<body onload="document.getElementById('captcha-form').focus()">

< ?php

/** Validate captcha */
if (!empty($_REQUEST['captcha'])) {
    if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
        $captcha_message = "Invalid captcha";
        $style = "background-color: #FF606C";
    } else {
        $captcha_message = "Valid captcha";
        $style = "background-color: #CCFF99";
    }

    $request_captcha = htmlspecialchars($_REQUEST['captcha']);

    echo <<<HTML
        <div id="result" style="$style">
        <h2>$captcha_message</h2>
        <table>
        <tr>
            <td>Session CAPTCHA:</td>
            <td>{$_SESSION['captcha']}</td>
        </tr>
        <tr>
            <td>Form CAPTCHA:</td>
            <td>$request_captcha</td>
        </tr>
        </table>
        </div>
HTML;
    unset($_SESSION['captcha']);
}

?>

<p><strong>Write the following word:</strong></p>

<form method="GET">
<img src="captcha.php" id="captcha" /><br/>

<!-- CHANGE TEXT LINK -->
<a href="#" onclick=" document.getElementById('captcha').src='captcha.php?'+Math.random(); document.getElementById('captcha-form').focus();"
    id="change-image">Not readable? Change text.</a><br/><br/>

<input type="text" name="captcha" id="captcha-form" autocomplete="off" /><br/>
<input type="submit" />

</form>

</body>
</html>

 

Thanks,

Bujji

bob_buzzardbob_buzzard

Rather than porting PHP, check out this developerforce wiki article which explains how to build it on Salesforce from the ground up:

 

http://wiki.developerforce.com/page/Adding_CAPTCHA_to_Force.com_Sites

bujjibujji
Thanks Bob, for replying fast. I already implemented the google re-captcha but i want some eye-catching captchas in my form. If you have implemented anything like that, please help me in that..

Thanks,
Bujji