Skip to content
minhaz edited this page Jul 8, 2017 · 6 revisions

How to use

CSRFP can be easily used to create a new web application or integrated with existing one! Here is step by step guide on integrating CSRFP with an existing web application in php, similar logic will apply while creating a new one.

Step 1 - Download and place the library in appropriate location

You can download the library's latest release from here

Now let us assume you have downloaded and placed the library in root directory of your web application. We are also assuming that you have an index.php file.

Step 2 - Include the library at the beginning of the file

You'd definitely want to include the library at the beginning of the php file, as CSRFP behaves like an interceptor, you'd want CSRFP logic be implemented before any web application logic. So include the library like:

<?php
include_once __DIR__ .'/libs/csrf/csrfprotector.php';

Step 3 - Call the init() function

Now that you have included the library only task left is to activate it in your page. In the simplest form you can call the library like

include_once __DIR__ .'/libs/csrf/csrfprotector.php';

//Initialise CSRFGuard library
csrfProtector::init();

This will cause library to pick up configurations from the config file and perform the validation and modification.

Repeat for each php file & you are secure !!!

You can also call init() with parameters for different page specific behaviour. Read our documentation on this