当前位置: 首页>>代码示例>>PHP>>正文


PHP CSRF::key方法代码示例

本文整理汇总了PHP中CSRF::key方法的典型用法代码示例。如果您正苦于以下问题:PHP CSRF::key方法的具体用法?PHP CSRF::key怎么用?PHP CSRF::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSRF的用法示例。


在下文中一共展示了CSRF::key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: open

 /**
  * Generates an opening HTML form tag
  *
  * Examples:
  * ~~~
  * // Form will submit back to the current page using POST
  * echo Form::open();
  *
  * // Form will submit to 'search' using GET
  * echo Form::open('search', array('method' => 'get'));
  *
  * // When "file" inputs are present, you must include the "enctype"
  * echo Form::open(NULL, array('enctype' => 'multipart/form-data'));
  * ~~~
  *
  * @param   mixed  $action  Form action, defaults to the current request URI, or Request class to use [Optional]
  * @param   array  $attrs   HTML attributes [Optional]
  * @return  string
  *
  * @uses    Request::uri
  * @uses    Request::current
  * @uses    Request::query
  * @uses    URL::site
  * @uses    URL::is_remote
  * @uses    URL::explode
  * @uses    HTML::attributes
  * @uses    Assets::css
  * @uses    CSRF::key
  * @uses    CSRF::token
  */
 public static function open($action = NULL, array $attrs = NULL)
 {
     if ($action instanceof Request) {
         // Use the current URI
         $action = $action->uri();
     }
     if ($action === '') {
         // Allow empty form actions (submits back to the current url).
         $action = '';
     } elseif (!URL::is_remote($action)) {
         // Make the URI absolute
         $action = URL::site($action);
     }
     // Add the form action to the attributes
     $attrs['action'] = $action;
     // Dynamically sets destination url to from action if exists in url
     if (Kohana::$is_cli === FALSE and $desti = Request::current()->query('destination') and !empty($desti)) {
         // Properly parse the path and query
         $url = URL::explode($action);
         //On seriously malformed URLs, parse_url() may return FALSE.
         if (isset($url['path']) and is_array($url['query_params'])) {
             //add destination param
             $url['query_params']['destination'] = $desti;
             //set the form action parameter
             $attrs['action'] = $url['path'] . URL::query($url['query_params']);
         }
     }
     // Only accept the default character set
     $attrs['accept-charset'] = Kohana::$charset;
     if (!isset($attrs['method'])) {
         // Use POST method
         $attrs['method'] = 'post';
     }
     $out = '<form' . HTML::attributes($attrs) . '>' . PHP_EOL;
     if (Gleez::$installed) {
         // Assign the global form css file
         Assets::css('form', 'media/css/form.css', array('weight' => 2));
         $action = md5($action . CSRF::key());
         $out .= self::hidden('_token', CSRF::token(FALSE, $action)) . PHP_EOL;
         $out .= self::hidden('_action', $action) . PHP_EOL;
     }
     return $out;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:73,代码来源:form.php


注:本文中的CSRF::key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。