Apache:如何在 cookie 环境变量中记录值?

Apache:如何在 cookie 环境变量中记录值?

我正在尝试使用以下方法记录 cookie 信息

CustomLog $PATH "%{cookie}i"

现在我想要将某些变量 ex( hb_name, hb_email, hb_cellno, hb_visit, hb_session) 从这个 cookie 记录到我的日志文件中。

我怎样才能从这个 cookie 中解析出特定的值并记录它们?

答案1

嗯,这完全取决于 cookie 的格式 - 但一点正则表达式应该可以帮助你到达那里。

假设你的 cookie 的内容是:hb_name:A,hb_email:[email protected],hb_cellno:1112223333

RewriteCond %{HTTP_COOKIE} hb_name:([^,]*)
RewriteRule ^ - [E=HBNAME:%1]
RewriteCond %{HTTP_COOKIE} hb_email:([^,]*)
RewriteRule ^ - [E=HBEMAIL:%1]
RewriteCond %{HTTP_COOKIE} hb_cellno:([^,]*)
RewriteRule ^ - [E=HBCELL:%1]

因此将每个值放入它们自己的 Apache 环境变量中,然后可以轻松记录:

CustomLog /some/file "name=%{HBNAME}e email=%{HBEMAIL}e cell=%{HBCELL}e"

如果您可以阐明您的 cookie 的确切格式以及您想要登录的确切格式,那么我可以提供更具体的说明。

相关内容