P3rsianc4T
سه شنبه 15 اردیبهشت 1394, 16:36 عصر
سلام خسته نباشید
کسی می تونه توی این مورد بنده رو راهنمایی کنه؟ از اضافه کردن کپچا به فرم گرفته تا سفارشی کردنش مثل رنگ فونتو بکگراندو ...
ممنون
aminar63
سه شنبه 15 اردیبهشت 1394, 17:30 عصر
به اینجا ی سری بزن
http://rezaonline.net/blog/category/php
اگر تونستی مثلا 3 رقمیش کنی یا بهینه ش کنی ؛یه ندا به ما بده
P3rsianc4T
سه شنبه 15 اردیبهشت 1394, 20:49 عصر
به اینجا ی سری بزن
http://rezaonline.net/blog/category/php
اگر تونستی مثلا 3 رقمیش کنی یا بهینه ش کنی ؛یه ندا به ما بده
این اکستنشن رو استفاده کردم واقعا عالیه همه جور گزینه ایم داره می تونین از این استفاده کنین
http://yii-demo.synet.sk/site/captchaExtended
اینم نتیجش
130918
MMSHFE
چهارشنبه 16 اردیبهشت 1394, 08:39 صبح
برای فعال کردن کپچای Yii کافیه توی کنترلری که میخواین کپچا رو استفاده کنید، این کد رو اضافه کنید:
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
حالا توی ویو این کد رو بگذارین:
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
دقت کنین که باید به مدلتون هم فیلد verifyCode رو اضافه کنید:
public $verifyCode;
public function rules()
{
return array(
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
درصورت نیاز میتونید با کمک on وجود verifyCode رو فقط توی سناریوی خاصی الزامی کنید.
MMSHFE
چهارشنبه 16 اردیبهشت 1394, 08:46 صبح
روش سفارشی سازی کپچای Yii :
کافیه یک کلاس توی مسیر protected/components بسازین با اسم دلخواه و توی فایلی به همون اسم هم ذخیره کنید. من اسم CaptchaAction رو گذاشتم و با نام protected/components/CaptchaAction.php ذخیره کردم. این کلاس باید از CCaptchaAction مشتق شده باشه و 2 متد داشته باشه: renderImage که وظیفه ساخت تصویر رو بعهده داره و generateVerifyCode که مسئول تولید کد تصادفیه. میتونید فیلدهای لازم برای سفارشی سازی کپچا رو هم بصورت public تعریف کنید. مثالی از یک کلاس که خودم نوشتم:
class CaptchaAction extends CCaptchaAction {
public $width = 190;
public $height = 75;
public $length = 4;
public $lineCount = 10;
public $circleCount = 10;
public $maxRadius = 50;
public $space = 35;
public function renderImage($code)
{
// Create image
$im = ImageCreate($this->width, $this->height);
// Create fixed colors
$backColor = ImageColorAllocate($im, 255, 255, 255);
// Asign font
$font = dirname(__FILE__) . '/snap.ttf';
// Start position of the text
$positionX = ($this->width - $this->space * $this->length) / 2;
// Rotation Direction (1: Anti-clockwise, -1: Clockwise)
$direction = 1;
// Fill the image with background color
ImageFill($im, $this->width / 2, $this->height / 2, $backColor);
// Write the text in the image using font, rotation, position, etc.
foreach(str_split($code) as $char) {
$textColor = ImageColorAllocate($im, rand() % 128, rand() % 128, rand() % 128);
// Calculate the bounding box of the text
$fontsize = $this->height * (rand(1, 5) * 0.05 + 0.2);
$box = ImageTTFBBox($fontsize, 0, $font, $code);
ImageTTFText($im, $fontsize, (rand() % 30 * $direction), $positionX, ($this->height - $box [5]) / 2, $textColor, $font, $char);
$direction = -$direction;
$positionX += $this->space;
}
// Add lines to the image
for($i = 0; $i < $this->lineCount; $i++) {
$x1 = rand() % $this->width;
$y1 = rand() % $this->height;
$x2 = rand() % $this->width;
$y2 = rand() % $this->height;
$lineColor = ImageColorAllocate($im, rand() % 128 + 127, rand() % 128 + 127, rand() % 96 + 159);
ImageLine($im, $x1, $y1, $x2, $y2, $lineColor);
}
// Add circles to the image
for($i = 0; $i < $this->circleCount; $i++) {
$cx = rand() % $this->width;
$cy = rand() % $this->height;
$rx = rand() % $this->maxRadius;
$ry = rand() % $this->maxRadius;
$start = rand() % 360;
$end = rand() % 360;
$lineColor = ImageColorAllocate($im, rand() % 128 + 127, rand() % 128 + 127, rand() % 96 + 159);
ImageArc($im, $cx, $cy, $rx, $ry, $start, $end, $lineColor);
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header('Content-Type: image/png');
ImagePNG($im);
}
protected function generateVerifyCode()
{
// Generate random code
$alpha = range('A', 'Z');
$code = '';
for($i = 0; $i < $this->length; $i++) {
$code .= $alpha [array_rand($alpha)];
}
return $code;
}
}
حالا کافیه توی کنترلر، برای استفاده از این کلاس برای تولید کپچا، بجای کدی که توی پست قبل گذاشتم، اینطوری کار کنید:
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CaptchaAction',
),
);
}
و برای سفارشی کردن (مثال) :
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CaptchaAction',
'length'=>6,
'width'=>250,
'height'=>50,
'space'=>30,
),
);
}
یعنی میتونید فیلدهای public کلاستون رو اینجا تغییر بدین و مقداردهی اولیه کنید تا از مقادیر پیشفرض خود کلاس استفاده نشه.
اگه جایی مشکلی بود بفرمایید تا توضیح بدم.
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.