Ouzo\Csrf\CsrfProtector::validate PHP 메소드

validate() 공개 정적인 메소드

public static validate ( )
    public static function validate()
    {
        $csrfToken = self::getCsrfToken();
        if (!isset($_COOKIE['csrftoken']) || $_COOKIE['csrftoken'] != $csrfToken) {
            self::_throwException();
        }
        $headerToken = Arrays::getValue(RequestHeaders::all(), 'X-Csrftoken');
        $postToken = Arrays::getValue($_POST, 'csrftoken');
        if ($headerToken != $csrfToken && $postToken != $csrfToken) {
            self::_throwException();
        }
    }

Usage Example

예제 #1
0
 public static function protect(Controller $controller)
 {
     $controller->before[] = function () {
         if (CsrfProtector::isMethodProtected(Uri::getRequestType())) {
             CsrfProtector::validate();
         }
         return true;
     };
     $controller->after[] = function () use($controller) {
         $controller->setCookie(array('name' => 'csrftoken', 'value' => CsrfProtector::getCsrfToken(), 'expire' => 0, 'path' => '/'));
         return true;
     };
 }