Welcome! Log In Create A New Profile

Advanced

Re: 2 variables inside if() ?

Maxim Dounin
October 22, 2010 04:18PM
Hello!

On Fri, Oct 22, 2010 at 12:42:08PM -0400, untamed wrote:

> Hello,
>
> I'm trying to compare 2 variables, like so (I've made sure the variables
> match):
>
> [code]if ($arg_hash !~ $sha1) {
> ...
> }[/code]
>
> However in error.log it says:
> [code]*1 "$sha1" does not match
> "a78c3ecd2e349d1f1050fa555842a60b585489d8"[/code]
>
> I've tried swapping the variables over and the same error occurs, so it
> looks like the variable after the comparison character(s) is considered
> a string by nginx.

Right hand side is considered to be regular expression in "~"
check, and compiled on configuration reading. No variables are
expected.

> Does anyone know of a way to do this? Or of a third party module which
> does this?

Any checks may be done within embedded perl.

In rewrite module you may do this by using combined variable and
regexp with backreferences (see man pcresyntax for details):

set $tt "$arg_hash:$sha1";

if ($tt !~ "^([^:]+):\1$") {
return 403;
}

Note well: before using "if" please make sure you've read and
understand http://wiki.nginx.org/IfIsEvil page.

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

2 variables inside if() ?

untamed October 22, 2010 12:42PM

Re: 2 variables inside if() ?

António P. P. Almeida October 22, 2010 01:50PM

Re: 2 variables inside if() ?

untamed October 22, 2010 04:05PM

Re: 2 variables inside if() ?

Maxim Dounin October 22, 2010 04:18PM

Re: 2 variables inside if() ?

untamed October 23, 2010 12:55AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 312
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready