PDA

View Full Version : خطای کپچا در Yii



beh3000
پنج شنبه 27 آذر 1393, 21:12 عصر
سلام

من از کپچایی که استاد شهرکی توی یکی از پست هاشون گذاشته بودن استفاده میکنم کار هم میکنه خیلی وقته ... یعنی کار میکرد الام که سیستم رو روشن کردم دیدم کار نمیکنه ... روی تصویر کپچا کلیک کردم و new tab باز کردم دیدم این خطا رو میده




CDbException


CDbConnection failed to open the DB connection.




کد کپچا :


<?php
$yii = dirname(__FILE__) . '/../../framework/yii.php';
$config = dirname(__FILE__) . '/../protected/config/main_cnfg.php';
require_once ($yii);
Yii::createWebApplication($config);


$height = 34;
$width = 100;
$length = 4;
$minLength=4;
$maxLength=5;
$lineCount = 3;
$circleCount = 2;
$maxRadius = 50;
$space = 15;


$length = mt_rand($minLength,$maxLength);

$alpha = range('A', 'Z');
$string = '';
for($i = 0; $i < $length; $i++)
$string .= substr(str_shuffle("0123456789"), 0, 1);


Yii::app()->session->open();
Yii::app()->session->add('captcha', strtolower($string));
header('Content-type: image/png');
$im = imagecreate($width, $height);
$backColor = imagecolorallocate($im, 255, 255, 255);
$font = './BYekan.ttf';
$fontsize = $height * 0.75;
$box = imagettfbbox($fontsize, 0, $font, $string);
$positionX = (($width - $space * $length) / 2)-10;
$direction = 1;


imagefill($im, $width / 2, $height / 2, $backColor);


for($i = 0; $i < $length; $i++) {


$char = substr($string, $i, 1);

$angle = rand(-20, 20);

$s=rand(1,2);
if($s==1)
$textColor = imagecolorallocate($im, 17,162,78);
elseif($s==2)
$textColor = imagecolorallocate($im, 34,34,34);


$xx1=rand(0,100);
$xx2=rand(0,100);
$yy1=rand(0,40);
$yy2=rand(0,40);
imageline($im, $xx1, $xx2, $yy1, $yy2, $textColor);

$xx1=rand(0,100);
$xx2=rand(0,100);
$yy1=rand(0,40);
$yy2=rand(0,40);
imageline($im, $xx1, $xx2, $yy1, $yy2, $textColor);

imagettftext($im, $fontsize, $angle, $positionX, ($height - $box [5]) / 2, $textColor, $font, $char);
$direction = -$direction;
$positionX += $space;
}


imagepng($im);
imagedestroy($im);
?>

MMSHFE
جمعه 28 آذر 1393, 09:16 صبح
توی فایل تنظیماتتون کامپوننت db رو تنظیم کنید که yii بتونه به دیتابیس وصل بشه. چک کنید سرویس mysql اجرا شده یا نه.

beh3000
جمعه 28 آذر 1393, 10:53 صبح
بقیه قسمت های سایت داره کار میکنه و مشکلی نداره با دیتا بیس .... فکر میکردم از قسمتی هست که دیتابیس sqllite تعریف کردم برای کامت چت ... اون قسمت رو برداشتم دوباره درست نشد ... این کامپوننت sqllite هست که برداشتمش


'dblite'=>array(
'class'=>'CDbConnection',
'connectionString' => 'sqlite:protected/data/chat.db',
'charset' => 'utf8',
),

beh3000
جمعه 28 آذر 1393, 16:07 عصر
بالاخره مشکلش رو پیدا کردم توی سایت همکدی آموزشی وجود داشت با این عنوان که : غیر فعال کردن csrf در بعضی از اکشن ها به این لینک (http://www.hamcodi.ir/article/392)

من از این استفاده کرده بودم برای همین اون کپچا لود نمیشد ... الان که غیر فعالش کردم درست شد ... حالا نمیدونم مشکل دقیقا از چی بود ... ولی اگه استاد بتونن که خیلی عالیه که هم اون کد کار کنه هم کپچا خطا نده

MMSHFE
شنبه 29 آذر 1393, 13:02 عصر
باید کپچا رو هم به لیست اکشنهایی که CSRF رو چک نمیکنن اضافه کنید.