Welcome! Log In Create A New Profile

Advanced

String comparison madness: "any string starting with '0' is false"

Posted by robbles 
String comparison madness: "any string starting with '0' is false"
June 30, 2010 11:04PM
Hello everyone,

[url=http://wiki.nginx.org/NginxHttpRewriteModule#if]The docs say[/url] that any string starting with a "0" is false. This was causing me problems with the following configuration block:

[code]
location ~ \.php$ {
root $webroot;
if ($cookie_staff)
{
fastcgi_pass 127.0.0.1:9001;
}
if ($cookie_staff = "")
{
fastcgi_pass 127.0.0.1:9000;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
[/code]

If $cookie_staff happens to start with "0", both IF comparisons return FALSE. This is horribly unintuitive to me, and because I missed that part of the documentation my raw PHP code was being leaked to some users for a long time.

I cannot solve this problem outside of Nginx, since the "staff" cookie is encrypted by PHP-FPM and I have no control over its contents.

My question is: how can I reliably detect the presence of the $cookie_staff, REGARDLESS of whether it begins with a "0" or not? Any advise would be greatly appreciated!



Edited 2 time(s). Last edit at 06/30/2010 11:06PM by robbles.
Re: String comparison madness: "any string starting with '0' is false"
July 01, 2010 12:39AM
Sorry, what I meant to ask was:

how can I reliably detect the presence [b]or absence[/b] of $cookie_staff, REGARDLESS of whether it begins with a "0" or not?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 108
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