[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How !isset in Ruby

Alexey Tafintsev

6/15/2008 10:57:00 AM

Hello people!
How !isset in Ruby?

example php
<?php
if(!isset($MY_UID))
{
//bla-bla
}
else
{
//bla-bla
}
?>
--
Posted via http://www.ruby-....

20 Answers

Oscar Del Ben

6/15/2008 11:09:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

What should !isset do? It's not obvious that we know php

2008/6/15, Alexey Tafintsev <alexey@goldtovar.com>:
>
> Hello people!
> How !isset in Ruby?
>
> example php
> <?php
> if(!isset($MY_UID))
> {
> //bla-bla
> }
> else
> {
> //bla-bla
> }
> ?>
>
> --
> Posted via http://www.ruby-....
>
>

Alexey Tafintsev

6/15/2008 11:35:00 AM

0

Oscar Del ben wrote:
> What should !isset do? It's not obvious that we know php
>
Oscar I need Basic Authenticate! I use Ruby CGI!


<?php

if(!isset($PHP_AUTH_USER))
// user unknown
{
Header("WWW-Authenticate: Basic realm=\"Admin Center\"");
Header("HTTP/1.0 401 Unauthorized");
exit();
}
else
// User - Ok, unknown password
{
// password insert
$password = "$PHP_AUTH_PW";
// пÑ?осмоÑ?Ñ? базÑ? для полÑ?Ñ?ения Ñ?еалÑ?ного паÑ?оля
$link = mysql_connect($dbhost, $dbuser, $dbpasswd);
mysql_select_db($dbname);
$result=mysql_query("SELECT password FROM auth WHERE
name=\"$PHP_AUTH_USER\"");
$row=mysql_fetch_array($result);
// пÑ?овеÑ?ка
if ($row==NULL) // in DB user unknown
{
Header("WWW-Authenticate: Basic realm=\"Admin Center\"");
Header("HTTP/1.0 401 Unauthorized");
exit();
}
else // In DB User Ok, check password
{
$real_password="$row[password]";
if ($real_password!=$password)
{
Header("WWW-Authenticate: Basic realm=\"Admin Center\"");
Header("HTTP/1.0 401 Unauthorized");
exit();
}
}
}

?>
--
Posted via http://www.ruby-....

Florian Gilcher

6/15/2008 12:22:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jun 15, 2008, at 1:34 PM, Alexey Tafintsev wrote:

> Oscar Del ben wrote:
>> What should !isset do? It's not obvious that we know php
>>
> Oscar I need Basic Authenticate! I use Ruby CGI!
>

What Oscar tried to tell you: while some of us know PHP, we are not
here to read it. It seems like you have a specific problem you need
solved. So please specify the problem in english, not in PHP (which is
commented in kyrillic...).

It just might be that the Ruby Solution could be very different from
one in PHP.

Regards,
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkhVCa0ACgkQJA/zY0IIRZYFJACgw2ZRMP0T5i/LP/+k+/pwp3WY
teEAn3lFjY5yq+0/nyX/3JgEBOBY74ym
=fB/D
-----END PGP SIGNATURE-----

Tor Erik Linnerud

6/15/2008 12:33:00 PM

0


> How !isset in Ruby?

Judging by http://uk2.php..., !(var.nil? rescue true) will
achieve something similar to !isset().

var.nil? rescue true
=> true

var = 123
var.nil? rescue true
=> false

var = nil
var.nil? rescue true
=> true

But I am not sure that it makes any sense when used with the Ruby CGI
library. An exception will be raised if a variable which doesn't exist
is accessed. All variables are generally evaluated to true, except for
those set to false or nil. If you want more help you have to tell us
what your problem is more exactly.

Tor Erik
--
Posted via http://www.ruby-....

Martin Boese

6/15/2008 12:38:00 PM

0


you can use defined?, however it will also hit on constants (classes), methods
and probably more ..:


if (!defined?($my_uid)) then

else

end


On Sunday 15 June 2008 11:56:54 Alexey Tafintsev wrote:
> Hello people!
> How !isset in Ruby?
>
> example php
> <?php
> if(!isset($MY_UID))
> {
> //bla-bla
> }
> else
> {
> //bla-bla
> }
> ?>



Robert Klemme

6/15/2008 1:13:00 PM

0

On 15.06.2008 14:37, Martin Boese wrote:
> you can use defined?, however it will also hit on constants (classes), methods
> and probably more ..:

For global variables testing for nil is probably better because they are
always and implicitly defined:

robert@fussel ~
$ ruby -e 'p $foo'
nil

robert@fussel ~
$ ruby -e 'p foo'
-e:1: undefined local variable or method `foo' for main:Object (NameError)

robert@fussel ~
$ ruby -e 'p @foo'
nil

Cheers

robert

Alexey Tafintsev

6/15/2008 2:35:00 PM

0

THANKS MANS !!!!
Working :-))))

----------------------------
#!c:/ruby/bin/ruby.exe

$kcode = "windows-1251"

require 'cgi'
cgi = CGI.new

user = ENV['AUTH_USER']
password = ENV['AUTH_PASSWD']

if (!defined?(ENV['AUTH_USER'])) then
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
else
if user == nil
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
else
real_password=password
if real_password!=password
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
end
end
end
----------------------------
--
Posted via http://www.ruby-....

Marc Heiler

6/15/2008 2:52:00 PM

0

> if (!defined?(ENV['AUTH_USER'])) then

you can omit the "then"

and you dont need the enclosing ()




if ! defined?(ENV['AUTH_USER'])

but i think this here might be cleaner



unless defined? ENV['AUTH_USER']
--
Posted via http://www.ruby-....

Alexey Tafintsev

6/15/2008 3:07:00 PM

0

Thank you Marc!!!! I rewrite this example :-)))
---------------------
#!c:/ruby/bin/ruby.exe

$kcode = "windows-1251"

require 'cgi'
cgi = CGI.new

def auth_lang
myauthlang = ENV['HTTP_ACCEPT_LANGUAGE']
case myauthlang
when /ru/
alang = "Ð?Ñ?ибка 401: НеобÑ?одима авÑ?оÑ?изаÑ?ия"
else
alang = "Error 401: Authorization Required"
end
end

user = ENV['AUTH_USER']
password = ENV['AUTH_PASSWD']

unless defined? user
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
puts auth_lang
else
if user == nil
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
puts auth_lang
else
real_password=password
if real_password!=password
puts cgi.header({"Status" => "401 Authorization Required",
"Type" => "text/html", "WWW-Authenticate" => "Basic realm=\"Web
Password\""})
puts auth_lang
end
end
end
---------------------



--
Posted via http://www.ruby-....

David A. Black

6/15/2008 3:11:00 PM

0

Hi --

On Mon, 16 Jun 2008, Alexey Tafintsev wrote:

> real_password=password
> if real_password!=password

I haven't looked at your code carefully but those two lines sort of
jumped out at me. Do you mean them to go in the opposite order?


David

--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS June 16-19 Berlin
ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.r... for details and updates!