From: Stefano Crocco Date: 2008-06-16T04:07:44+09:00 Subject: Re: How !isset in Ruby On Sunday 15 June 2008, Alexey Tafintsev wrote: > Hello again! > This code don't work! Please, help... > > --------------------- > #!c:/ruby/bin/ruby.exe > > $kcode = "windows-1251" > > require 'cgi' > cgi = CGI.new > > login_successful = false > > if ENV['AUTH_USER'].nil? and ENV['AUTH_PASSWD'].nil? > user = ENV['AUTH_USER'] > pass = ENV['AUTH_PASSWD'] > else if user == 'test' and pass == 'test' > login_successful = true > end > end > > if (!login_successful) > puts cgi.header({"Status" => "401 Authorization Required", "Type" => > "text/html", "WWW-Authenticate" => "Basic realm=\"Web Password\""}) > puts "401 Authorization Required" > else > puts cgi.header > puts "OK" > end > --------------------- It would be helpful saying what exactly isn't working (that is: what did you expect and what instead happened, which error message you got, if any, and so on). At any rate, I think there's a mistake in the first if. The line if ENV['AUTH_USER'].nil? and ENV['AUTH_PASSWD'].nil? tests that neither the AUTH_USER nor the AUTH_PASSWD variables are defined, In the following two lines, you put the values of the two environment variables (which, remember, don't exist) in the two variables user and pass. This means that both user and pass will always be nil. Then, there's the fact that you don't use those two variables (but maybe, the code you show here isn't complete). By the way, in ruby the structure of an if-else expression is: if ... ... elsif ... ... else ... end Note that the third line is elsif, not else if. I don't think this can cause problems in your situation, but I suggest you to change it all the same. I hope this helps Stefano