PHP code example of banujan6 / csrf-handler

1. Go to this page and download the library: Download banujan6/csrf-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

banujan6 / csrf-handler example snippets


	composer 

	
		//If you are using any frameworks, It will load autoload.php automatically. So you don't need.
		

 
  rfhandler\csrf as csrf;

<form>
  <input type="hidden" name="_token" value=" echo csrf::token(); 

  $isValid = csrf::get(); // return TRUE or FALSE
  
  if ( $isValid ) {
  
    //Do something if valid
  
  } else {
  
    //Do something if not vaid
  
  }

  $isValid = csrf::post(); // return TRUE or FALSE
  
  if ( $isValid ) {
  
    //Do something if valid
  
  } else {
  
    //Do something if not vaid
  
  }

  $isValid = csrf::all(); // return TRUE or FALSE
  
  if ( $isValid ) {
  
    //Do something if valid
  
  } else {
  
    //Do something if not vaid
  
  }

  csrf::flushToken(); // will destroy all active tokens