The latest thinkphp v5.2 work order system Show TokenBuildBehavior.class.php Source code
Return
Download The latest thinkphp v5.2 work order system:
download TokenBuildBehavior.class.php Source code
- Download The latest thinkphp v5.2 work order system Source code - Type:.php
- <?php
- // +----------------------------------------------------------------------
- // | TOPThink [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2010 http://topthink.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: liu21st <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- namespace Behavior;
- /**
- * 系统行为扩展:表单令牌生成
- */
- class TokenBuildBehavior {
- public function run(&$content){
- if(C('TOKEN_ON')) {
- list($tokenName,$tokenKey,$tokenValue)=$this->getToken();
- $input_token = '<input type="hidden" name="'.$tokenName.'" value="'.$tokenKey.'_'.$tokenValue.'" />';
- $meta_token = '<meta name="'.$tokenName.'" content="'.$tokenKey.'_'.$tokenValue.'" />';
- if(strpos($content,'{__TOKEN__}')) {
- // 指定表单令牌隐藏域位置
- $content = str_replace('{__TOKEN__}',$input_token,$content);
- }elseif(preg_match('/<\/form(\s*)>/is',$content,$match)) {
- // 智能生成表单令牌隐藏域
- $content = str_replace($match[0],$input_token.$match[0],$content);
- }
- $content = str_ireplace('</head>',$meta_token.'</head>',$content);
- }else{
- $content = str_replace('{__TOKEN__}','',$content);
- }
- }
- //获得token
- private function getToken(){
- $tokenName = C('TOKEN_NAME',null,'__hash__');
- $tokenType = C('TOKEN_TYPE',null,'md5');
- if(!isset($_SESSION[$tokenName])) {
- $_SESSION[$tokenName] = array();
- }
- // 标识当前页面唯一性
- $tokenKey = md5($_SERVER['REQUEST_URI']);
- if(isset($_SESSION[$tokenName][$tokenKey])) {// 相同页面不重复生成session
- $tokenValue = $_SESSION[$tokenName][$tokenKey];
- }else{
- $tokenValue = is_callable($tokenType) ? $tokenType(microtime(true)) : md5(microtime(true));
- $_SESSION[$tokenName][$tokenKey] = $tokenValue;
- if(IS_AJAX && C('TOKEN_RESET',null,true))
- header($tokenName.': '.$tokenKey.'_'.$tokenValue); //ajax需要获得这个header并替换页面中meta中的token值
- }
- return array($tokenName,$tokenKey,$tokenValue);
- }
- }
downloadTokenBuildBehavior.class.php Source code
- Download The latest thinkphp v5.2 work order system Source code
Related Source Codes/Software:
V3.3.6 Workerman high-performance PHP Socket (framework) - High performance PHP Socket framework Workerman re... 2017-05-03
The phosphor meeting room reservation system MRBS (loop reservation v16.0) - The phosphor meeting room reservation system MRBS ... 2017-05-03
IDC v5.2.3 agent center - IDC Centre IDC for exploitation is a PHP+MySQL age... 2017-05-03
Zen master v9.0.1 project management software - Zen is the first domestic open source project mana... 2017-05-03
Ray speed v7.03 employee files management system - Employee files project is various, and some conten... 2017-05-03
HITCMS Haitian responsive electronic mechanical v3.0 foreign trade website source code - HITCMS Haitian response electronic machinery trade... 2017-05-03
Ray v7.02 speed survey system - Lightning speed survey system is a. NET+MSSQL deve... 2017-05-03
Cool HITCMS reactive black v3.0 enterprise website source code - HITCMS-Haitian response black enterprises website ... 2017-05-03
WebOA v17.2 network office automation system - WebOA network using b/s structure development of o... 2017-05-03
Pure imitation of han site source code, one a 】 【 c9cms kernel v1.0 - Generic http://www.wufazhuce.com/Han one ·
Config... 2017-05-04
zone.js - Implements Zones for JavaScript
... 2017-05-11
dragonfly - A Ruby gem for on-the-fly processing - suitable fo... 2017-05-11
oh-my-fish - The Fishshell Framework. 2017-05-11
canvas-lms - The open LMS by Instructure, Inc. 2017-05-11
ledger - Double-entry accounting system with a command-line... 2017-05-11
Python - My Python Examples
http://w... 2017-05-11
blade - 2017-05-11
LaZagne - Credentials recovery project 2017-05-10
Pull-to-Refresh.Rentals-iOS - This project aims to provide a simple and customiz... 2017-05-10
spoon - Distributing instrumentation tests to all your And... 2017-05-10