Example of U Method Encryption Passing Parameter Function in thinkPHP

  • 2021-10-13 06:56:28
  • OfStack

In this paper, an example is given to describe the function of encrypting and passing parameters by U method in thinkPHP. Share it for your reference, as follows:

The U method in thinkPHP is used to assemble URL addresses. The corresponding URL address can be automatically generated according to the current URL mode and settings. For basic use, please refer to https://www.ofstack.com/article/51057. htm

The specific code is as follows:


<?php
/**
 *  Encryption of Simple Symmetric Encryption Algorithm 
 * @param String $string  Strings to be encrypted 
 * @param String $skey  Encryption 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));
}
/**
 *  Decryption of Simple Symmetric Encryption Algorithm 
 * @param String $string  Strings to be decrypted 
 * @param String $skey  Decryption 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));
}
/**
 Put the above two functions in the Common Under function.php In the public function. 
 Usage: Common words get Reference transmission 
  Front end: <a href="<{:U('Index/view',array('id'=>encode($data['id']),'name'=>encode($data['title'])))}>" rel="external nofollow" ><{$data.title}></a>
  Backstage: view Method: $id = decode(trim(I("get.id"))); Can be restored 
 view In the template: <font color="red"><{$Think.get.name|decode}></font>
**/
/* It is recommended that key Modify yourself, try not to be too long, otherwise url Very long, appropriate, encryption performance is very good, pro-test */

For more readers interested in thinkPHP related contents, please check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".

I hope this article is helpful to PHP programming based on ThinkPHP framework.


Related articles: