Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSRF token for ajax

I have a problem with forms submitted with ajax. I do my forms with Zend Framework. Some are real forms so I add a Hash element. Others are for small operations (like upvote and downvote here) so I do them with links.

My problem is that I need to use ajax especially for the small forms (the links). I see a lot of questions but nothing comprehensive enough to solve the problem. Is there a detailed description on how to get csrf token working smoothly when forms are submitted via ajax? preferably with Zend Framework but general PHP answers will help too.

like image 395
samquo Avatar asked Jan 22 '11 20:01

samquo


1 Answers

You don't need a CSRF token. You case use the HTTP_X_REQUESTED_WITH method (see e.g. here).

like image 76
Artefacto Avatar answered Oct 11 '22 23:10

Artefacto