Sunday, June 17, 2012

Fixing The CSRF token could not be verified

"The CSRF token could not be verified", if you get this message while using YII Framework. the issue can happen in
1.You are not using CHtml Form widget
2.You are not using CActiveFormWidget
3.You are using cusom ajax handlers

If you are using CHtml Form widget or CActiveForm widget the Yii Framework automatically validate CSRF token, if we using custom form or custom jquery ajax methods we should pass YII_CSRF_TOKEN to POST request, this may solve the above issue

$csrfToken = Yii::app()->request->csrfToken; // 
will return the csrf token associated with the context, you can now use that csr token to pass in jquery ajax functions

to check csrfvalidation enabled in application use the following method to get status

Getting CSRF Token from javascript


Lokashree sam said...

It was a great information and Its really worth reading it. The author did an mind blowing work by describing each and every concept in detail. Thanks for such an informative post. Please keep up your good work.
Engineering Colleges In Chennai, Nautical Science Colleges In Chennai

Radley Co Tad said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP Training in chennai | PHP Training Course

PHP Training in chennai | Online PHP Course

HawksCode said...

Web design services has gained popularity in the last few decades, since the internet has become accessible to the common people.A web design company providing web design services that not only concentrates in building a remarkable and inspiring user-friendly website, but also undertakes the mission of endorsing it on the World Wide Web successfully.

summer internship said...

Indian Cyber Army is now coming up with Summer Internship in “Ethical hacking & Cyber Crime Investigation”. Candidates have to get themselves registered to be a part of this Summer Internship program starting from 15th June. Here you will acknowledge the tact to observe cyber crime and tricks to fight against it. The internship content is especially designed by Indian Cyber Army’s expert for aspiring hackers and cyber security geeks.