<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[xajax Forums - Captcha]]></title>
	<link rel="self" href="http://community.xajaxproject.org/feed/atom/topic/6941/"/>
	<updated>2010-03-09T08:40:27Z</updated>
	<generator>PunBB</generator>
	<id>http://community.xajaxproject.org/topic/6941/captcha/</id>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/29225/#p29225"/>
			<content type="html"><![CDATA[a simple sample here...
[code]
**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();
[/code]]]></content>
			<author>
				<name><![CDATA[ExSystem]]></name>
				<uri>http://community.xajaxproject.org/user/4353/</uri>
			</author>
			<updated>2010-03-09T08:40:27Z</updated>
			<id>http://community.xajaxproject.org/post/29225/#p29225</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28408/#p28408"/>
			<content type="html"><![CDATA[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:
[code]
<?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);
?>
[/code]

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.

[code]
<?php
$valor=$_SESSION['numeroaleatorio'];
class Securimage{
    var $codigo;
    public function __construct(){
        global $valor;
        return $this->codigo=$valor;
    }
}
?>
[/code]
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?
[code]
require_once("securimage.php");
$securimage= new Securimage(); //Instance sht securimage object.
$securimage->codigo;
[/code]]]></content>
			<author>
				<name><![CDATA[luismarcelo]]></name>
				<uri>http://community.xajaxproject.org/user/3957/</uri>
			</author>
			<updated>2009-07-16T02:24:53Z</updated>
			<id>http://community.xajaxproject.org/post/28408/#p28408</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28192/#p28192"/>
			<content type="html"><![CDATA[Ed,

Nice!  Thanks for sharing that code sample.]]></content>
			<author>
				<name><![CDATA[CtC]]></name>
				<uri>http://community.xajaxproject.org/user/934/</uri>
			</author>
			<updated>2009-06-08T20:06:20Z</updated>
			<id>http://community.xajaxproject.org/post/28192/#p28192</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28191/#p28191"/>
			<content type="html"><![CDATA[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:

[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>
[/code]

See if this fits your need.

Ed]]></content>
			<author>
				<name><![CDATA[edrobinson]]></name>
				<uri>http://community.xajaxproject.org/user/693/</uri>
			</author>
			<updated>2009-06-08T16:40:06Z</updated>
			<id>http://community.xajaxproject.org/post/28191/#p28191</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28190/#p28190"/>
			<content type="html"><![CDATA[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]]></content>
			<author>
				<name><![CDATA[CtC]]></name>
				<uri>http://community.xajaxproject.org/user/934/</uri>
			</author>
			<updated>2009-06-08T14:57:07Z</updated>
			<id>http://community.xajaxproject.org/post/28190/#p28190</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/28185/#p28185"/>
			<content type="html"><![CDATA[I'm having the same problem. It won't show up because its a script.]]></content>
			<author>
				<name><![CDATA[ebrand]]></name>
				<uri>http://community.xajaxproject.org/user/2854/</uri>
			</author>
			<updated>2009-06-07T23:58:46Z</updated>
			<id>http://community.xajaxproject.org/post/28185/#p28185</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Captcha]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/25629/#p25629"/>
			<content type="html"><![CDATA[hi...  how can i make a captcha using Xajax...?

thanks in advance...]]></content>
			<author>
				<name><![CDATA[kof3d]]></name>
				<uri>http://community.xajaxproject.org/user/2636/</uri>
			</author>
			<updated>2008-09-06T02:04:07Z</updated>
			<id>http://community.xajaxproject.org/post/25629/#p25629</id>
		</entry>
</feed>
