Hi all,
Instead of generating a fresh ‘captcha’ code when I click on ‘Get a new Code’ I get the below output:
{"hash1":744,"hash2":744,"url":"\/test\/site\/captcha?v=51491e4327c85"}
I am at a loss. I have gone through the forums but have drawn a blank. Has anyone else had this problem.
Output from Firebug:
3975
I am using Yii 1.1.13
My set up is below.
The instructions for setting up a Yii app seems pretty clear…
On the server the ‘framework’ files are in the the ‘private’ folder which is not accessible online.
This is the file structure:
httpdocs
.../test
… index.php
…/protected
httpsdocs
private
.../YiiRoot
…/framework
However when I set up the folders and files with the above instructions, the web application did not work.
Currently all folders and sub folders permissions are ‘rxwr-wr-w’.
Below are my code for for the website.
This is the code in my /test/protected/yiic.php file:
<?php
// change the following paths if necessary
$yiic=dirname(__FILE__).'/../../private/YiiRoot/framework/yiic.php';
$config=dirname(__FILE__).'/config/console.php';
require_once($yiic);
This is my ‘/test/index.php’ file contents.
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../../private/YiiRoot/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
require_once($yii);
Yii::createWebApplication($config)->run();
NB: All other Yii functionality works such as ‘crumbs’ and form error checking and sending emails.
The ‘.htaccess’ file in the same directory as the above ‘index.php’ file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
SetEnv APPLICATION_ENV development
/config/main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Model:
public $name;
public $email;
public $phone;
public $subject;
public $verifyCode;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, phone', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
SiteController:
class SiteController extends Controller
{
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
/**
* I have added a contact us form on the index page, which is a modified version of the standard ContactForm.
*
*/
public function actionIndex()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$phone='=?UTF-8?B?'.base64_encode($model->phone).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-type: text/plain; charset=UTF-8";
mail(Yii::app()->params['adminEmail'],$phone,$model->name,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('index',array('model'=>$model));
}
/**
* @return array action filters
*/
public function filters()
{
return array( 'accessControl', // perform access control for CRUD operations
);
}
/** * Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'actions'=>array('create', 'captcha'),
'users'=>array('*'),
),
);
}
Finally: /views/site/index.php
<?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; ?>
I hope that this is comprehensive enough. Any help would be appreciated.
Thanks in advance.