遇到一个瓶颈,当COOKIE数据达到5K以上的时候,只好将COOKIE数据进行压缩,以减少数据的大小
- <?php
- //十进制转到其他制
- function dec2any($num, $base = 62, $index = false)
- {
- if (!$base) {
- $base = strlen($index);
- } elseif (!$index) {
- $index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
- }
- $out = "";
- for ($t = floor(log10($num) / log10($base)); $t >= 0; $t--) {
- $a = floor($num / pow($base, $t));
- $out = $out . substr($index, $a, 1);
- $num = $num - ($a * pow($base, $t));
- }
- return $out;
- }
- function any2dec($num, $base = 62, $index = false)
- {
- if (!$base) {
- $base = strlen($index);
- } elseif (!$index) {
- $index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
- }
- $out = 0;
- $len = strlen($num) - 1;
- for ($t = 0; $t <= $len; $t++) {
- $out = $out + strpos($index, substr($num, $t, 1)) * pow($base, $len - $t);
- }
- return $out;
- }
- ?>
加网-分享按钮!
http://share.baidu.com/