Skip to content

Setting up CSRF Protector PHP in your web application

minhaz edited this page Jul 27, 2014 · 8 revisions

Task 1: Download the library from

  1. Master Version
  2. NoJs supported version

Which one to use?

Task 2: Place the library in appropriate location

We are assuming that, you have a web application party mate (url http://partymate.com) which allows user to add parties and add users to parties, so that they are notified about party information. And you download the library to root directory of the application and extract it. So you application now has a new folder csrfp. The directory structure of this folder looks like:

|_csrfp
  |_js
    |_csrfprotector.js
  |_libs
    |_csrf
      |_csrfpJsFileBase.php
      |_csrfprotector.php
    |_config.sample.php
  |_log

Task 3: Setup the configuration file

Config file by default is shipped as csrfp\libs\config.sample.php which means you need to rename it to config.php & do following changes!

Note: in the config file, you need to modify 'jsUrl' before you
      can use csrfprotector php library. Its very easy!

jsUrl is the absolute url of the javascript file, that will be set to client with each HTML output. So in the above case the jsUrl paramter in config.php file needs to be set to http://partymate.com/csrfp/js/csrfprotector.js

Task 4: Configure according to your needs

You must read Configurations to understand different parameters in config file and make changes according to your needs.

Task 5 Include the library in your files and run

We'd recommend you include this library in every file, of your application to make your server, secure against CSRF attacks. See How to use to learn more about implementing CSRFP in your web app!