CsrfToken

trait CsrfToken

Methods

public static csrf_token() No description
public static csrf_token_verify($token) No description

Details

at line 7

csrf_token()

public static csrf_token()
at line 18

csrf_token_verify()

public static csrf_token_verify($token)

Parameters

$token

Source code

<?php
	
	namespace App\Khan\Component\Router\Components;
	
	trait CsrfToken {

		  public static function csrf_token(){
            if (empty($_SESSION['token'])) {
                if (function_exists('mcrypt_create_iv')) {
                    $_SESSION['token'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
                } else {
                    $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32));
                }
            }
            return $_SESSION['token'];
          }

          public static function csrf_token_verify($token){
            if (!empty($token) && !empty($_SESSION['token'])) {
                if (hash_equals($_SESSION['token'], $token)) {
                    return true;
                } else {
                    return false;
                }
            }
          }

	}