csrf::token PHP Méthode

token() public static méthode

public static token ( )
    public static function token()
    {
        if ($sessionToken = Session::get('csrf_token')) {
            return $sessionToken;
        }
        $token = noise(64);
        Session::put('csrf_token', $token);
        return $token;
    }

Usage Example

Exemple #1
0
 /**
  * Generates an opening HTML form tag.
  *
  * @param   string  form action attribute
  * @param   array   extra attributes
  * @param   array   hidden fields to be created immediately after the form tag
  * @return  string
  */
 public static function open($action = NULL, $attr = array(), $hidden = NULL)
 {
     // Make sure that the method is always set
     empty($attr['method']) and $attr['method'] = 'post';
     if ($attr['method'] !== 'post' and $attr['method'] !== 'get') {
         // If the method is invalid, use post
         $attr['method'] = 'post';
     }
     if ($action === NULL) {
         // Use the current URL as the default action
         $action = url::site(Router::$complete_uri);
     } elseif (strpos($action, '://') === FALSE) {
         // Make the action URI into a URL
         $action = url::site($action);
     }
     // Set action
     $attr['action'] = $action;
     // Only show the CSRF field when form method is POST
     $hidden_field = $attr['method'] === 'post' ? form::hidden('form_auth_token', csrf::token()) . "\n" : '';
     // Form opening tag
     $form = '<form' . form::attributes($attr) . '>' . "\n" . $hidden_field;
     // Add hidden fields immediate after opening tag
     empty($hidden) or $form .= form::hidden($hidden);
     return $form;
 }
All Usage Examples Of csrf::token