www.webdeveloper.com
Results 1 to 7 of 7

Thread: Checking if there is anything in a variable

  1. #1
    Join Date
    Sep 2004
    Posts
    398

    Checking if there is anything in a variable

    i would like to check if there is anything in a variable, for my login script, i have tried

    Code:
    #!/perl/bin/perl
    
    my $foo = "foo";
    my $bar = "bar";
    
    print "Content-type: text/html\n\n";
    
    if ($foo =="" && $bar =="")
    {
      print "You have not entered a password/username!";
    }
    else
    {
      print "you would be logged in...";
    }
    but it doesn't work. Does anyone know how it can be done?

  2. #2
    Join Date
    Mar 2004
    Posts
    282
    try the 'eq' operator.

    Code:
    #!/perl/bin/perl
    
    my $foo = "foo";
    my $bar = "bar";
    
    print "Content-type: text/html\n\n";
    
    if ($foo eq "" && $bar eq "")
    {
      print "You have not entered a password/username!";
    }
    else
    {
      print "you would be logged in...";
    }
    or you could use the length() function.

    -Will

  3. #3
    Join Date
    Sep 2004
    Posts
    398
    the problem with that is, that if there is a user name but not a password, it doesn't tell you you've forgotten it. is there an 'or' that could be put instead of && ?

    EDIT:
    or can it be done with 2 if statements?
    i have tried this code, but it didn't work, can you see the problem?

    Code:
    #!/perl/bin/perl
    
    my $foo = "foo";
    my $bar = "bar";
    
    print "Content-type: text/html\n\n";
    
    if ($foo eq "")
    {
      print "You have not entered a password/username!";
    }
    else
    {
    if ($bar eq "")
    {
      print "You have not entered a password/username!";
    }
    else
    {
      print "you would be redirected...";
    }
    };
    EDIT 2:
    After i got the eq's right i found out it works!
    Thanks for the help!
    Last edited by Scleppel; 10-29-2004 at 01:27 PM.

  4. #4
    Join Date
    Sep 2004
    Posts
    398
    Now i've got that bit done, instead of redirecting the user, it prints "Status: 302 Moved Location: "

    My code is:
    Code:
    #!/perl/bin/perl
    use CGI qw/:standard/;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    
    my $foo = param('foo2');
    my $bar = param('bar2');
    my $redirect = "http://".$foo.":".$bar."\@82.36.196.155/secure/";
    
    print "Content-type: text/html\n\n";
    
    if ($foo eq "")
    {
      print "You have not entered a password/username!";
    }
    else
    {
    if ($bar eq "")
    {
      print "You have not entered a password/username!";
    }
    else
    {
      print redirect($redirect);
    }
    };

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You can't output data before sending a redirect request, if I'm not mistaken. Try...

    Code:
    #!/perl/bin/perl
    use CGI qw/:standard/;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    
    my $foo = param('foo2');
    my $bar = param('bar2');
    my $redirect = "http://".$foo.":".$bar."\@82.36.196.155/secure/";
    
    if ($foo eq "")
    {
      print "Content-type: text/html\n\n";
      print "You have not entered a password/username!";
    }
    else
    {
    if ($bar eq "")
    {
      print "Content-type: text/html\n\n";
      print "You have not entered a password/username!";
    }
    else
    {
      print redirect($redirect);
    }
    };
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  6. #6
    Join Date
    Sep 2004
    Posts
    398
    Thank you, that worked!

  7. #7
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Happy to help.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles