src/CsrfProtection.php
public function getCookie()
    {
        $request = Request::current();
        $settings = CsrfSettings::singleton();

        if ($request instanceof WebRequest){
            $existingCookie = $request->cookie(self::TOKEN_COOKIE_NAME, false);

            if ($existingCookie){
                $this->currentCookie = $existingCookie;
            }
        }

        if (!$this->currentCookie) {
            $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345689.;,!$%^&*()-=+";
            $cookie = "";
            for ($x = 0; $x < self::TOKEN_COOKIE_LENGTH; $x++) {
                $rand = rand(0, strlen($chars) - 1);
                $char = $chars[$rand];

                if (rand(0, 1) == 1) {
                    $char = strtolower($char);
                }

                $cookie .= $char;
            }

            $this->currentCookie = $cookie;

            HttpResponse::setCookie(self::TOKEN_COOKIE_NAME, $cookie, 0, '/', parse_url($settings->domain, PHP_URL_HOST), false, true);
        }

        return $this->currentCookie;
    }
public function getCookie()
    {
        $request = Request::current();
        $settings = CsrfSettings::singleton();

        if ($request instanceof WebRequest){
            $existingCookie = $request->cookie(self::TOKEN_COOKIE_NAME, false);

            if ($existingCookie){
                $this->currentCookie = $existingCookie;
            }
        }

        if (!$this->currentCookie) {
            $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345689.;,!$%^&*()-=+";
            $cookie = "";
            for ($x = 0; $x < self::TOKEN_COOKIE_LENGTH; $x++) {
                $rand = rand(0, strlen($chars) - 1);
                $char = $chars[$rand];

                if (rand(0, 1) == 1) {
                    $char = strtolower($char);
                }

                $cookie .= $char;
            }

            $this->currentCookie = $cookie;

            HttpResponse::setCookie(self::TOKEN_COOKIE_NAME, $cookie, 0, '/', parse_url($settings->domain, PHP_URL_HOST), false, true);
        }

        return $this->currentCookie;
    }
public function getCookie ( ) { $ request = Request :: current ( ) ; $ settings = CsrfSettings :: singleton ( ) ; if ( $ request instanceof WebRequest ) { $ existingCookie = $ request -> cookie ( self :: TOKEN_COOKIE_NAME , false ) ; if ( $ existingCookie ) { $ this -> currentCookie = $ existingCookie ; } } if ( ! $ this -> currentCookie ) { $ chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345689.;,!$%^&*()-=+" ; $ cookie = "" ; for ( $ x = 0 ; $ x < self :: TOKEN_COOKIE_LENGTH ; $ x ++ ) { $ rand = rand ( 0 , strlen ( $ chars ) - 1 ) ; $ char = $ chars [ $ rand ] ; if ( rand ( 0 , 1 ) == 1 ) { $ char = strtolower ( $ char ) ; } $ cookie .= $ char ; } $ this -> currentCookie = $ cookie ; HttpResponse :: setCookie ( self :: TOKEN_COOKIE_NAME , $ cookie , 0 , '/' , parse_url ( $ settings -> domain , PHP_URL_HOST ) , false , true ) ; } return $ this -> currentCookie ; }
Returns the current cookie being used for CSRF or generates one if one doesn't exist.
Returns the current cookie being used for CSRF or generates one if one doesn t exist .