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


PHP CSRF::token方法代码示例

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


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

示例1: open

 /**
  * Generates an opening HTML form tag.
  *
  *     // 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   form action, defaults to the current request URI, or [Request] class to use
  * @param   array   html attributes
  * @return  string
  * @uses    Request::instance
  * @uses    URL::site
  * @uses    HTML::attributes
  */
 public static function open($action = NULL, array $attributes = 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 (strpos($action, '://') === FALSE) {
         // Make the URI absolute
         $action = URL::site($action);
     }
     // Add the form action to the attributes
     $attributes['action'] = $action;
     // Only accept the default character set
     $attributes['accept-charset'] = Kohana::$charset;
     if (!isset($attributes['method'])) {
         // Use POST method
         $attributes['method'] = 'post';
     }
     // Only render the CSRF field when the POST method is used
     $hidden_csrf_field = $attributes['method'] == 'post' ? self::hidden('form_auth_id', CSRF::token()) : '';
     return '<form' . HTML::attributes($attributes) . '>' . $hidden_csrf_field;
 }
开发者ID:rukku,项目名称:SwiftRiver,代码行数:44,代码来源:form.php

示例2: __constructStatic

 public static function __constructStatic()
 {
     if (!isset($_COOKIE['csrfToken'])) {
         self::$token = Helper::randStr(10);
         setcookie("csrfToken", self::$token, 0, "/", Lobby::getHostname());
     } else {
         self::$token = $_COOKIE['csrfToken'];
     }
 }
开发者ID:LobbyOS,项目名称:server,代码行数:9,代码来源:CSRF.php

示例3: execute

 /**
  * Processes the request, executing the controller action that handles this
  * request, determined by the [Route].
  *
  * 1. Before the controller action is called, the [Controller::before] method
  * will be called.
  * 2. Next the controller action will be called.
  * 3. After the controller action is called, the [Controller::after] method
  * will be called.
  *
  * By default, the output from the controller is captured and returned, and
  * no headers are sent.
  *
  *     $request->execute();
  *
  * @return  Response
  * @throws  Request_Exception
  * @throws  HTTP_Exception_404
  * @uses    [Kohana::$profiling]
  * @uses    [Profiler]
  */
 public function execute()
 {
     if (!$this->_route instanceof Route) {
         throw new HTTP_Exception_404('Unable to find a route to match the URI: :uri', array(':uri' => $this->_uri));
     }
     if (!$this->_client instanceof Request_Client) {
         throw new Request_Exception('Unable to execute :uri without a Kohana_Request_Client', array(':uri' => $this->_uri));
     }
     // Add custom header for CSRF protection where an Ajax
     // request is made via HTTP POST
     if ($this->method() === 'POST' and $this->is_ajax()) {
         $this->headers('X-CSRF-Token', CSRF::token());
     }
     return $this->_client->execute($this);
 }
开发者ID:rukku,项目名称:SwiftRiver,代码行数:36,代码来源:request.php

示例4: execute

 /**
  * Processes the request, executing the controller action that handles this
  * request, determined by the [Route].
  *
  * 1. Before the controller action is called, the [Controller::before] method
  * will be called.
  * 2. Next the controller action will be called.
  * 3. After the controller action is called, the [Controller::after] method
  * will be called.
  *
  * By default, the output from the controller is captured and returned, and
  * no headers are sent.
  *
  *     $request->execute();
  *
  * @return  Response
  * @throws  Request_Exception
  * @throws  HTTP_Exception_404
  * @uses    [Kohana::$profiling]
  * @uses    [Profiler]
  */
 public function execute()
 {
     if (!$this->_external) {
         $processed = Request::process($this, $this->_routes);
         if ($processed) {
             // Store the matching route
             $this->_route = $processed['route'];
             $params = $processed['params'];
             // Is this route external?
             $this->_external = $this->_route->is_external();
             if (isset($params['directory'])) {
                 // Controllers are in a sub-directory
                 $this->_directory = $params['directory'];
             }
             // Store the controller
             $this->_controller = $params['controller'];
             // Store the action
             $this->_action = isset($params['action']) ? $params['action'] : Route::$default_action;
             // These are accessible as public vars and can be overloaded
             unset($params['controller'], $params['action'], $params['directory']);
             // Params cannot be changed once matched
             $this->_params = $params;
         }
     }
     if (!$this->_route instanceof Route) {
         return HTTP_Exception::factory(404, 'Unable to find a route to match the URI: :uri', array(':uri' => $this->_uri))->request($this)->get_response();
     }
     if (!$this->_client instanceof Request_Client) {
         throw new Request_Exception('Unable to execute :uri without a Kohana_Request_Client', array(':uri' => $this->_uri));
     }
     // Add custom header for CSRF protection where an Ajax
     // request is made via HTTP POST
     if ($this->method() === 'POST' and $this->is_ajax()) {
         $this->headers('X-CSRF-Token', CSRF::token());
     }
     return $this->_client->execute($this);
 }
开发者ID:aliyubash23,项目名称:SwiftRiver,代码行数:58,代码来源:Request.php

示例5:

				<img class="img-responsive" src="images/<?php 
echo $p->filename;
?>
" alt="<?php 
echo $p->caption;
?>
">
			</div>
		</div>
		<div class="col-lg-6 col-lg-offset-3">
			<form method="post" action="photo.php?id=<?php 
echo $p->id;
?>
">
				<input type="hidden" name="token" value="<?php 
echo CSRF::token();
?>
">
				<h4>Add your comment</h4>
				
				<?php 
echo $msg;
?>
				<div class="form-group">
					<label>Name</label>
					<input class="form-control" type="text" placeholder="Enter your Name" name="author" value="">
				</div>
				
				<div class="form-group">
					<label>Comment</label>
					<textarea class="form-control" placeholder="Enter your Comment" name="body"></textarea>				
开发者ID:shubhamoy,项目名称:photolia,代码行数:31,代码来源:photo.php

示例6: csrf

 /**
  * Creates CSRF token input
  *
  * @param   string  $id      ID e.g. uid [Optional]
  * @param   string  $action  Action [Optional]
  *
  * @return  string
  *
  * @uses    CSRF::token
  */
 public static function csrf($id = '', $action = '')
 {
     return self::hidden('token', CSRF::token($id, $action));
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:14,代码来源:form.php

示例7: form

 /**
  * Generates the CSRF form input
  * @uses    Form
  * @param   string  $namespace
  * @return  string  generated HTML
  */
 public static function form($namespace = 'default')
 {
     return Form::hidden('csrf_' . $namespace, CSRF::token($namespace));
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:10,代码来源:csrf.php


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