# Comparing two variables

**URL:** <https://www.ruby-forum.com/t/comparing-two-variables/208244>\
**Category:** NGINX\
**Created:** [June 13, 2011, 9:45am UTC](https://www.ruby-forum.com/t/comparing-two-variables/208244 "2011-06-13T09:45:16Z")\
**Posts on this page:** 4\
**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:** [June 13, 2011, 9:45am UTC](https://www.ruby-forum.com/t/comparing-two-variables/208244/1 "2011-06-13T09:45:16Z")

</div>

hi

i wrote a module which is extracting certain values out of a session  
that is stored in memcache and stores it into a variable in my nginx  
config. so this seems to work fine so far.

now i’m trying to compare $uri with one of these variables and do a  
rewrite accordingly. but it seems that the if that comes from nginx’  
rewrite module cannot only compare a variable with a static string or  
a static regex, but not with another variable.

is that true?

i’ve tried following and except this if everything works:

* * *

```
// get session from memcache
eval $session {
    set $memc_key $cookie_session_id;
    memc_pass session_memcache;
}

// extract username from session
php_session_parse $user $session

```

“symfony/user/sfUser/attributes|s:10:“subscriber”;s:11:“getNickname””;

```
// strip the formatting of the value, so that f.e. s:6:"drevil"

```

becomes drevil  
php\_session\_strip\_formatting $stripped\_user $user;

```
// show all profile data
if ($stripped_user ~* $uri)
{
    rewrite . d41d8cd98f00b204e9800998ecf8427e:profile_prod$uri:full 

```

last;  
}

```
// show public profile
rewrite . d41d8cd98f00b204e9800998ecf8427e:profile_prod$uri last;
```

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [June 13, 2011, 10:01am UTC](https://www.ruby-forum.com/t/comparing-two-variables/208244/2 "2011-06-13T10:01:56Z")

</div>

i just found that with an = it works, but i need the comparison to be  
case insensitive…

i was thinking if there is any way to lowercase or uppercase both  
strings before the comparison, then i could do an =.

is there any way to lowercase or uppercase a string? otherwise i could  
also write a very small module for that.

i would prefer to don’t have to use lua

Posted at Nginx Forum:

> **[Re: comparing two variables](https://forum.nginx.org/read.php?2,206345,206350#msg-206350)**
>
> hi i wrote a module which is extracting certain values out of a session that is stored in memcache and stores it into a variable in my nginx config. so this seems to work fine so far. now i'm trying to compare $uri with one of these variables and do...

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [June 13, 2011, 10:12pm UTC](https://www.ruby-forum.com/t/comparing-two-variables/208244/3 "2011-06-13T22:12:31Z")

</div>

Hello!

On Mon, Jun 13, 2011 at 03:44:42PM +0800, Mauro Stettler wrote:

> is that true?

Yes, regexps must be static. You may try something like this as a  
workaround:

```
set $tmp "$var1:$var2";
if ($tmp ~* "^(.*):\1$") {
    ...
}

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [June 14, 2011, 4:18am UTC](https://www.ruby-forum.com/t/comparing-two-variables/208244/4 "2011-06-14T04:18:23Z")

</div>

thanks a lot, thats a really smart idea and it works.

i’m thinking if i should maybe write a module which is simply  
uppercasing or lowercasing a variable, so that i don’t need this  
workaround anymore. do you think there would be other people happy  
about having that? via google i haven’t found any existing module to  
do that.

anyway for now i’m going to deploy the workaround.

thanks
