Topic: Captcha

hi...  how can i make a captcha using Xajax...?

thanks in advance...

Re: Captcha

I'm having the same problem. It won't show up because its a script.

Re: Captcha

Can you provide some details?  I'm sure there is a way to accomplish the task, but we need to know more about what you've tried and the error or issue you've experienced.

Thanks

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: Captcha

ebrand,

I have been experimenting with an open source captcha tool named securimage and it seems to work just fine with XAJAX.

Here's some sample code:

<?php
/*
    Simple CAPTCHA using securimage from
    http://www.phpcaptcha.org/
*/
ob_start();
session_start(); //Must run a session for securimage to function...
require_once("xajax/xajax_core/xajax.inc.php"); 
$xajax = new xajax();                                                     
require_once("securimage/securimage.php");
$securimage= new Securimage(); //Instance sht securimage object.

function test($dta)
{
    global $securimage;
    $resp=new xajaxResponse();    
        extract($dta);
    //Validate the user's entered security code.
    if ($securimage->check($captcha_code) === false) 
      $resp->alert("You entered the wrong security code.");
    else
      $resp->alert("You entered the correct security code.");

    return $resp; 
}
//$xajax->setflag('debug', true);  //Uncomment to turn on xajax debugging.
$xajax->register(XAJAX_FUNCTION,"test"); 
$xajax->processRequest(); 
?>
<html>
<head>
<? $xajax->printJavascript('xajax'); ?>
<title>test</title>
<style>
label{
    font-weight: bold;
    width: 150px;
    text-align: right;
}
</style>
</head>
<body>
<center>
<form id="form1" onsubmit="xajax_test(xajax.getFormValues('form1')); return false;">
<!-- Generate the captcha image via securimage -->
<img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA"/><br/>
<!-- The input where the user enters the displayed code -->
<input type="text" id="captcha_code" name="captcha_code" size="10" maxlength="6"/><br/>
<input type="button" value="submit" onclick="xajax_test(xajax.getFormValues('form1')); return false;"/>
</form>
</center>
</body>
</html>

See if this fits your need.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Captcha

Ed,

Nice!  Thanks for sharing that code sample.

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

6 (edited by luismarcelo 2009-07-16 3:32:41 AM)

Re: Captcha

Sorry but I have the same problem, which is running which shows the security code.
Which shows the security code is: securimage / securimage_show.php, that it is:

<?php
  $ancho=100;
  $alto=30;
  $imagen=imageCreate($ancho,$alto);
  $amarillo=ImageColorAllocate($imagen,226,226,226);
  ImageFill($imagen,0,0,$amarillo);
  $rojo=ImageColorAllocate($imagen,255,0,0);
  //Variables
  $DesdeLetra = "A";
  $HastaLetra = "Z";
  $DesdeNumero = 1000;
  $HastaNumero = 9999;

  $letraAleatoria1 = chr(rand(ord($DesdeLetra), ord($HastaLetra)));
  $letraAleatoria2 = chr(rand(ord($DesdeLetra), ord($HastaLetra)));
  $letraAleatoria3 = chr(rand(ord($DesdeLetra), ord($HastaLetra)));
  $numeroAleatorio = rand($DesdeNumero, $HastaNumero);

  //$valoraleatorio=rand(100000,999999);
  $valoraleatorio=$letraAleatoria1.$letraAleatoria2.$letraAleatoria3.$numeroAleatorio;
  //$valoraleatorio=rand(100000,999999);
  session_start();
  $_SESSION['numeroaleatorio']=$valoraleatorio;
  ImageString($imagen,5,25,5,$valoraleatorio,$rojo);
  for($c=0;$c<=5;$c++)
  {
    $x1=rand(0,$ancho);
    $y1=rand(0,$alto);
    $x2=rand(0,$ancho);
    $y2=rand(0,$alto);
    ImageLine($imagen,$x1,$y1,$x2,$y2,$rojo);
  }
   //global $imagen;
   Header ("Content-type: image/jpeg");
   ImageJPEG ($imagen);
   ImageDestroy($imagen);
?>

But what is the code:
require_once ( "securimage / securimage.php");
Get the picture session, is the only way?
I was thinking about this solution. But I do not work.

<?php
$valor=$_SESSION['numeroaleatorio'];
class Securimage{
    var $codigo;
    public function __construct(){
        global $valor;
        return $this->codigo=$valor;
    }
}
?>

I do not want to be in doubt please.
how would the script of "securimage.php"

And in the "single source" (the ED) would take the value in this way?

require_once("securimage.php");
$securimage= new Securimage(); //Instance sht securimage object.
$securimage->codigo;

Re: Captcha

a simple sample here...

**using xajax 0.5 and smarty******
********global.php, include this file first**********
/**
 * 
 */
function Render() {
    if (array_key_exists('xjxfun', $_GET)) {
        return;
    }
    if (function_exists('Action' . $_GET['action'])) {
        $mAction = 'Action' . $_GET['action'];
        unset($_GET['action']);
        $mParams = array ();
        foreach ($_GET as $mValue) {
            $mParams[] = $mValue;
        }
        call_user_func_array($mAction, $mParams);
    }
    else {
        ActionDefault();
    }
}

*************index.php****************

/**
 *
 */
function ActionDefault() {
    //....other code
    //processing login form.
    TApp::getXajax()->registerFunction('XajaxDraw');
    TApp::getXajax()->registerFunction('XajaxCheckCaptcha');
    TApp::getXajax()->processRequest();
    
    $mSmarty = new TBiddingSmarty(TApp::getSettings());
    $mSmarty->assign('AjaxScript', TApp::getXajax()->printJavascript());
    $mSmarty->display('index.html');
}


/**
 * @return    xajaxResponse
 */
function XajaxDraw() {
    $mRes = new xajaxResponse();
    $mCaptchaCode = chr(mt_rand(65, 90));
    $mCaptchaCode .= chr(mt_rand(65, 90));
    $mCaptchaCode .= chr(mt_rand(65, 90));
    $mCaptchaCode .= chr(mt_rand(65, 90));
    $mCaptcha = 'Captcha.php?action=Draw&Code=' . $mCaptchaCode;
    $mRes->assign('CaptchaImage', 'src', $mCaptcha);
    $mRes->assign('CaptchaHidden', 'value', $mCaptchaCode);
    return $mRes;
}


/**
 * @param    array            $Args
 * @return    xajaxResponse
 */
function XajaxCheckCaptcha($Args) {
    $mRes = new xajaxResponse();
    if ($Args[0] == $Args[1]) {
        $mRes->script('document.LogInForm.submit();');
    }
    else {
        $mRes->assign('LogInStateLi', 'style.visibility', 'visible');
        $mRes->assign('LogInStateLi', 'innerHTML', 'Wrong captacha!');
    }
    return $mRes;
}

Render();

***************Captcha.php***********
/**
 * 
 * @param    string    $Code
 */
function ActionDraw($Code) {
    header("Content-type: image/GIF");
    $mCaptcha = imagecreate(67, 24);
    $mBgColor = imagecolorallocate($mCaptcha, 245, 245, 245);
    imagefill($mCaptcha, 0, 0, $mBgColor);
    
    for($i = 0; $i < 4; ++$i) {
        $mColor = imagecolorallocate($mCaptcha, rand(100, 255), rand(0, 100), rand(100, 255));
        imagestring($mCaptcha, 5, 13 + $i * 11, 5, $Code[$i], $mColor);
    }
    for($i = 0; $i < 100; ++$i) {
        $mOtherColor = imagecolorallocate($mCaptcha, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($mCaptcha, rand() % 70, rand() % 30, $mOtherColor);
    }

    imagegif($mCaptcha);
    imagedestroy($mCaptcha);
}

/**
 * 
 */
function ActionDefault() {
   Redirect('index.php');
}

Render();