Not able to get uid from nginx for first request

2019-07-14 04:39发布

问题:

I have installed uid module in nginx , also have added configs related for uid.

userid          on;
userid_name     uid;
userid_expires  365d;
userid_p3p      'policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"';

I am successfully getting uid but only after first request.on my first request it just sets uid.I can't access it in php.
I can see

Set-Cookie uid=fwAAAVCl6NEEvCbKAwMEAg==; expires=Sat, 16-Nov-13 07:18:41 GMT; path=/

in my firebug for first request's Response Headers.
And my nginx access log is written with following logs for first request.

127.0.0.1 - - [16/Nov/2012:12:48:41 +0530] "GET /_p.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2536 "http://127.0.0.1/_p.php" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100403 Fedora/3.6.3-4.fc13 Firefox/3.6.3" "-"

127.0.0.1 - - [16/Nov/2012:12:48:41 +0530] "GET /_p.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2158 "http://127.0.0.1/_p.php" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100403 Fedora/3.6.3-4.fc13 Firefox/3.6.3" "-"

127.0.0.1 - - [16/Nov/2012:12:48:44 +0530] "GET /_p.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2536 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100403 Fedora/3.6.3-4.fc13 Firefox/3.6.3" "-"

Can someone tell me how to get uid for my first request in php?

回答1:

Got it.

location ~ \.php$ {
    root           /usr/share/nginx/html;
    try_files $uri =404;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  UID_GOT $uid_got;
    fastcgi_param  UID_SET $uid_set;
    include        fastcgi_params;
}

Added these nginx configurations , when first request is called I get uid inside $_SERVER['UID_SET'] and for other requests uid is set in $_SERVER['UID_GOT'].



标签: nginx php