user3504970
user3504970

Reputation: 117

keep getting internal error with apache perl

I have simple sign in page. when i enter abc and 123 as login credentials it should redirect me to login successful page but it keeps giving me the internal error.If login information is not abc and 123 it should redirect to wrong login page. Maybe my if statement is wrong. Can you check my code out? Please.

#!/usr/bin/perl

use CGI qw( :standard );

$user = param( "user" );
$password = param( "password" );

$user = param( "user" );
$password = param( "password" );

if ($user == "abc") && ($password == "123")
print redirect ( "../../login.htm" );
}

if (!$user ne "abc") || (!$password ne "123")
print redirect ( "../../wrong.htm" );
}

Upvotes: 0

Views: 49

Answers (1)

Dave Cross
Dave Cross

Reputation: 69314

I put your code into a file called test.cgi and then checked it for compilation errors.

$ perl -c test.cgi
syntax error at test.cgi line 11, near ") &&"
Unmatched right curly bracket at test.cgi line 13, at end of line
Unmatched right curly bracket at test.cgi line 17, at end of line
test.cgi had compilation errors.

So that gives you some places to look. The syntax you're using for your if statements is broken in a couple of ways.

Here are a few suggestions that will help you write Perl code more efficiently.

  1. Just because CGI programs are written to run on a web server, that doesn't mean they can only run on a web server. Get into the habit of checking for compilation errors outside of the web server environment.
  2. When you are testing CGI programs running on a web server, then the errors and warnings will be written to the web server error log. Get into the habit of looking there for more details about problems that you find.
  3. Always add use strict and use warnings to your code and fix the problems that they show you. There is at least one other problem in your code that will be found by use warnings.

Finally, writing a CGI program is not the best way to write a web application in 2015. Please look at some alternatives.

Upvotes: 1

Related Questions