Search code examples
phpajaxsecurityzend-frameworkcsrf

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.


Solution

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