ホームページ  >  記事  >  php教程  >  NGINX userid 分析、解码

NGINX userid 分析、解码

WBOY
WBOYオリジナル
2016-06-06 20:11:061782ブラウズ

生成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。

default: /* AF_INET */
                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">// 用PHP解码nginx userid
$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]));

参考文章:
http://www.lsproc.com/blog/nginx_userid_decode/

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。