NGINX userid Analysis, decoding

Source: Internet
Author: User
Tags sin vars

The NGINX userid parses and decodes the code that generates the UserID in the HTTP/modules/ngx_http_userid_filter_module.c about 550 rows or so. Uid_set is composed of 4 UInt32, the more useful is the second unit32, is the UserID generation time. The fourth one is an increment value to0x03030302as the initial value, increment 0x100 each time. default:/*af_inet*/Sin= (structsockaddr_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 <0x03030302) {Sequencer_v2=0x03030302; }//decoding nginx userid with PHP$str = $_request["UID"]?: $_cookie['UID'];function Nginx_userid_decode ($str) {returnUnpack'N', Base64_decode (Str_replace (' ','+', $STR)));} $hash=Nginx_userid_decode ($STR); Var_dump ($hash);d Ate_default_timezone_set ("UTC"); Var_dump (Date ("y-m-d h:i:s", $hash [2]); Reference article: http://www.lsproc.com/blog/nginx_userid_decode/


[Practice OK] Examples of cookies handled in Nginx configuration files Nginx Cookie Justwinit 2014-11-1 15:32Big | medium | small
Web2.0»web Server Reviews (0)
Background: In the Nginx cache plug-in, personal blog if the login state when access to the home page or cache, after logging in with HTTPS management, but often access is HTTP, access to the cached page, I can not know whether they have logged on the same time, Can not see their own more hidden and pinned blog post, here, issued can be processed through the Nginx cookie to read the cache, when the discovery of this cookie, the call to delete the cache interface to delete the same time to jump to the back-end HTTPS management page, and then solve the problem.
————————————————————————————————————————————————————

1. Extract the entire contents of the cookie into a variable, which can then be referenced when needed, such as logging into the log,
if ($http _cookie ~* "(. *) $") {
Set $all _cookie $;
}
The variable $all_cookie gets the value of the cookie and can be used to transport it.

2. Extract the value of a specified cookie and use it as needed, such as assigning a value to X-real-ip,
if ($http _cookie ~* "pass_ip= (. +) (?:; |$)") {
Set $one _cookie $;
}
The variable $one_cookie gets the value of the cookie with the key value pass_ip, which can be used for shipping.

3. Add content to cookies in scenes such as proxy/fcgi, such as telling the backend that you are the front.

Proxy_set_header Cookie "$http _cookie; node_id=018 "
    1. Text

A cookie called node_id is added here, and of course, in this case, the ID of the front end can be passed to backend:
Proxy_set_header X-cdn-id "018";
The backend can get the assignment by $_server[' http_x_cdn_id ').

Excerpt from: http://www.lc365.net/blog/b/24592/
————————————————————————————————————————————————————————————————————————————
Oneself to engage in the situation of their own practice for a moment:
View Plainprint?
  1. Set $flag 0;
  2. Set $userid 0; #登录用户的id作为cookie值放cookie了.
  3. ......
  4. Location ~. *\. (PHP|PHP5)? $
  5. {#实现Https访问博文及非主页面的列表下用Ctrl +f5 Delete cached files accessed by the foreground user
  6. if ( $request _uri ~* "^/post/([0-9]+)/? ( [0-9]+]?/?  ([0-9]+)/?$ ") #如URL转写后请求到博文及列表 (excluding home page and admin function) is condition 1.
  7. {
  8. Set $flag "${flag}1";
  9. }
  10. if ($http _cache_control ~ "No-cache") #如果是上面博文连接且用了Ctrl +f5 is the condition 2, which implements the deletion of the generated cache file, the front-end user accesses to the latest update post page.
  11. {
  12. Set $flag "${flag}1";
  13. }
  14. if ($flag = "011") {
  15. Rewrite ^ (. *) $/purge $ last;
  16. }
  17. Fastcgi_pass Unix:/tmp/php-cgi.sock;
  18. Fastcgi_index index.php;
  19. include fastcgi.conf;
  20. }


delcache.php
View Plainprint?
  1. <?php
  2. https://justwinit.cn/post/4082/
  3. Header ("content-type:text/html;  Charset=utf-8 ");
  4. function Purgecache ()
  5. {
  6. $cacheRoot = "/data/cache/ngx_fcgi_cache";
  7. $url = "get://". $_server["Http_host"].   $_server["Request_uri"];
  8. if (emptyempty ($_server["Http_host"]) | | emptyempty ($_server["Request_uri")) {
  9. Die (' Please enter the correct URL, check the host parameter in and the URI parameter is correct.  ‘);
  10. }
  11. $MD 5 = MD5 ($url);
  12. $cacheFile = $cacheRoot. '/'. substr ($md 5,-1, 1). '/'. substr ($md 5,-3, 2). '/'.  $MD 5;
  13. //echo $url. "  <br> ";
  14. //echo $cacheFile. "  <br> ";
  15. if (! File_exists ($cacheFile)) {
  16. //echo (' cache does not exist.  ‘);
  17. }
  18. if (@unlink ($cacheFile)) {
  19. //echo ' Clear cache succeeded.  ‘;
  20. } Else {
  21. //echo ' Clear cache failed.  ‘;
  22. }
  23. //file_put_contents ("/tmp/jack.txt", Var_export ($_server,true), file_append);
  24. if (isset ($_server["https"]) && $_server["https"] = = "on") {//Compatible Access is from HTTPS:  There is no $_server["HTTPS" variable on HTTP access.
  25. $url = "https://". $_server["Http_host"].   $_server["Request_uri"];
  26. }ElseIf (isset ($_cookie[' USERPSW ') &&isset ($_cookie[' userid '])) {//  Compatible is when the administrator logs on after having a cookie, access to turn off HTTPS, no cache.
  27. $url = "https://". $_server["Http_host"].   $_server["Request_uri"];
  28. }
  29. else{
  30. $url = "http://". $_server["Http_host"].   $_server["Request_uri"];
  31. }
  32. Flush ();
  33. Ob_clean ();
  34. //header ("Location:". $url);//Prevent multiple cycle jumps, use front-end jump.
  35. echo "<meta http-equiv= ' refresh ' content= ' 0;url= $url '/>";
  36. exit;
  37. }
  38. Purgecache ()
  39. ?>




NGINX userid Analysis, decoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.