生成userid的代码在 http/modules/ngx_http_userid_filter_module.c 大概550行左右。 uid_set 是4个uint32构成的,其中比较有用的是第二个unit32,是userid的生成时间。第四个是一个递增值 以 0x03030302 为初始值,每次递增0x100。 default: /* AF_INET */
生成userid的代码在 http/modules/ngx_http_userid_filter_module.c 大概550行左右。
uid_set 是4个uint32构成的,其中比较有用的是第二个unit32,是userid的生成时间。第四个是一个递增值 以 0x03030302 为初始值,每次递增0x100。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | default :
sin = (struct sockaddr_in *) c->local_sockaddr;
ctx->uid_set[0] = sin->sin_addr.s_addr;
break ;
}
} else {
ctx->uid_set[0] = htonl(conf->service);
}
ctx->uid_set[1] = htonl((uint32_t) ngx_time());
ctx->uid_set[2] = htonl(start_value);
ctx->uid_set[3] = htonl(sequencer_v2);
sequencer_v2 += 0x100;
if (sequencer_v2
<pre class = "brush:php;toolbar:false" >
$str = $_REQUEST [ "uid" ] ?: $_COOKIE [ 'uid' ];
function nginx_userid_decode( $str )
{
return unpack( 'N*' , base64_decode ( str_replace ( ' ' , '+' , $str )));
}
$hash = nginx_userid_decode( $str );
var_dump( $hash );
date_default_timezone_set( "UTC" );
var_dump( date ( "Y-m-d H:i:s" , $hash [2]));
|
Nach dem Login kopieren
参考文章:
http://www.lsproc.com/blog/nginx_userid_decode/
原文地址:NGINX userid 分析、解码, 感谢原作者分享。