if(!function_exists('base64_encrypt')){ function base64_encrypt($str){ $key = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $result = strtr(base64_encode($str), '+', '_'); $result = strtr($result, '/', '\\'); $max = strlen($result) - 2; if($max > strlen($key)){ $max = strlen($key) - 1; } $index = rand(0, $max); $char = $key[$index]; $result = $char.substr(substr_replace($result, $char, $index, 0), 0); return $result; } } if(!function_exists('base64_decrypt')){ function base64_decrypt($str){ $key = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $char = substr($str, 0, 1); $str = substr($str, 1); $index = strpos($key, $char); $str = substr($str, 0, $index).substr($str, $index + 1); $str = strtr($str, '_', '+'); $str = strtr($str, '\\', '/'); return base64_decode($str); } }
注意事項:$key字符串不能出現重複字符 不然會致使解密失敗!code