Home > Article > Backend Development > Analysis of the function of encrypted parameters passed by U method in thinkPHP
This article mainly introduces the U method encrypted parameter transfer function in thinkPHP, and analyzes the relevant operating techniques of thinkPHP using U method to encrypt parameters when passing parameters through get, combined with examples. Friends who need it can refer to it
The example in this article describes the U method encrypted parameter passing function in thinkPHP. Share it with everyone for your reference, the details are as follows:
The U method in thinkPHP is used to assemble the URL address. The corresponding URL address can be automatically generated based on the current URL mode and settings.
The specific code is as follows:
<?php /** * 简单对称加密算法之加密 * @param String $string 需要加密的字串 * @param String $skey 加密EKY */ function encode($string = '', $skey = 'yourkey') { $strArr = str_split(base64_encode($string)); $strCount = count($strArr); foreach (str_split($skey) as $key => $value) $key < $strCount && $strArr[$key].=$value; return str_replace(array('=', '+', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr)); } /** * 简单对称加密算法之解密 * @param String $string 需要解密的字串 * @param String $skey 解密KEY */ function decode($string = '', $skey = 'yourkey') { $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', '+', '/'), $string), 2); $strCount = count($strArr); foreach (str_split($skey) as $key => $value) $key <= $strCount && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0]; return base64_decode(join('', $strArr)); } /** 将以上两个函数放在Common下的function.php公共函数中。 用法:常用语get传参 前端:<a href="<{:U('Index/view',array('id'=>encode($data['id']),'name'=>encode($data['title'])))}>" rel="external nofollow" ><{$data.title}></a> 后台:view方法中:$id = decode(trim(I("get.id")));即可还原 view模板中:<font color="red"><{$Think.get.name|decode}></font> **/ /*建议将key自行修改,尽量不要太长,不然url很长,适当即可,加密性能很好,亲测*/
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Analysis of the N method of ThinkPHP
Usage analysis of the I method of ThinkPHP
The above is the detailed content of Analysis of the function of encrypted parameters passed by U method in thinkPHP. For more information, please follow other related articles on the PHP Chinese website!