# Variable variables?

**URL:** <https://www.ruby-forum.com/t/variable-variables/215379>\
**Category:** NGINX\
**Created:** [January 2, 2012, 4:41pm UTC](https://www.ruby-forum.com/t/variable-variables/215379 "2012-01-02T16:41:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 2, 2012, 4:41pm UTC](https://www.ruby-forum.com/t/variable-variables/215379/1 "2012-01-02T16:41:26Z")

</div>

Hi,

Nginx provides the value of the cookie “foo” in $cookie\_foo . Is it  
possible to read “foo” from the URL? In PHP you would use two dollar  
signs for this kind of indirection.

Drupal sets the name of session cookie based on the cookie domain. I  
am running SSI (reading from Redis via Webdis) and I would like to  
read some user specific information which is stored in a Redis hash  
named after the sesion name with a key of the value of the session  
cookie. So the SSI command would be something include  
virtual="/user/SESSnameofthesession". So I need to rewrite that into  
something like  
/redis/SESSnameofthesession/${COOKIE\_$SESSnameofthesession}.

Thanks

Karoly N.

Ps. Sorry if i sent two copies of this.

---

<div class="post-metadata">

**Author:** ![Karoly\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85e7bf/32.png) [@Karoly\_N](https://www.ruby-forum.com/u/Karoly_N)\
**Post date:** [January 3, 2012, 6:19am UTC](https://www.ruby-forum.com/t/variable-variables/215379/2 "2012-01-03T06:19:58Z")

</div>

On Mon, Jan 2, 2012 at 11:40 PM, Karoly N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Nginx provides the value of the cookie “foo” in $cookie\_foo . Is it  
> possible to read “foo” from the URL? In PHP you would use two dollar  
> signs for this kind of indirection.

Well, it is trivial with ngx\_lua’s set\_by\_lua config directive:

```
location /blah {
    set_by_lua $arg_value
        'local arg_name = ngx.var.cookie_foo
         return ngx.var["arg_" .. arg_name]';

    # reference $arg_value in later phase config directives here...
}

```

See the documentation for details:

```
http://wiki.nginx.org/HttpLuaModule#set_by_lua

```

Regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![Karoly\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85e7bf/32.png) [@Karoly\_N](https://www.ruby-forum.com/u/Karoly_N)\
**Post date:** [January 3, 2012, 6:26am UTC](https://www.ruby-forum.com/t/variable-variables/215379/3 "2012-01-03T06:26:08Z")

</div>

On Mon, Jan 2, 2012 at 11:40 PM, Karoly N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Drupal sets the name of session cookie based on the cookie domain. I  
> am running SSI (reading from Redis via Webdis) and I would like to  
> read some user specific information which is stored in a Redis hash  
> named after the sesion name with a key of the value of the session  
> cookie. So the SSI command would be something include  
> virtual=“/user/SESSnameofthesession”. So I need to rewrite that into  
> something like /redis/SESSnameofthesession/${COOKIE\_$SESSnameofthesession}.

I think you may consider replacing webdis with ngx\_redis2:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Also, you may consider replacing SSI with content\_by\_lua because the  
latter provides a full-fledged scripting language as well as the same  
nonblocking network I/O capabilities (with ngx\_redis2, among other  
things).

Regards,  
-agentzh
