對於前后端交互過程中的提交請求,一般會使用token的方式來防刷。
但是后端生成的token傳給前端,前端提交請求的數據一般會有urldecode處理。
這時候 如果token中包含 + 等特殊字符 數據將被改寫。
解決方案:
1.生成token時 先base64 加密 然后替換特殊字符 + = /
2.解token時 先替換特殊字符 + = / 后base64解密
function base_encode($str) {
$src = array("/","+","=");
$dist = array("_a","_b","_c");
$old = base64_encode($str);
$new = str_replace($src,$dist,$old);
return $new;
}
function base_decode($str) {
$src = array("_a","_b","_c");
$dist = array("/","+","=");
$old = str_replace($src,$dist,$str);
$new = base64_decode($old);
return $new;
}
urlencode:http://www.php.net/manual/zh/function.urlencode.php
base64_decode:http://www.t086.com/code/php/function.php-base64_encode.php
