Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect to another page using cgi

Status
Not open for further replies.

khanUlm

Programmer
Aug 29, 2013
1
DE
want to redirect the client to the another page after the password is unmatched. I have a cgi at server end and need to redirect.

My code :
#!/usr/bin/perl

use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
require 'globalvariables.pl';
# Get STDIN: the input from the post
read(STDIN, $stdin, $ENV{'CONTENT_LENGTH'});
#print "Content-Type: text/plain\n\n" ;
#print $stdin;

#variables values
$filename = 'annotationTools/perl/testlocation.txt';
$actualpass = " ";
$current_username = '';
$current_password = '';
$current_startpage = '';
$current_lastpage = '';
$current_collection = '';

#values of the post
($current_username,$current_password)= split(/&/,$stdin);

#print $temp_user;
#print $temp_pass;

if(!open(FP,$LM_HOME.$filename)) {
print "Status: 404\n\n";
return;
}
@lines = readline(FP);
@twodimarray;
$lines=0;
$passwordmatch =0;
foreach $i (@lines) {
($login, $passwd, $from,$till,$collection)= split(/,/,$i);
$indexlog = index($login, '=');
$indexpass = index($passwd, '=');
$indexstart = index($from, '=');
$indexend = index($till, '=');
$indexcollection = index($collection, '=');

$loginval = substr $login, $indexlog+1;
$passwdval = substr $passwd, $indexpass+1;
$startval= substr $from, $indexstart+1;
$endval= substr $till, $indexend+1; $collectionval = substr $collection, $indexcollection+1;

$twodimarray = $loginval;
$twodimarray = $passwdval;
$twodimarray = $startval;
$twodimarray = $endval;
$twodimarray = $collectionval;
$lines++;
}

for ($init = 0; $init < $lines; $init++) {
$usertemp = $twodimarray;

if($current_username eq $usertemp)
{
$passtemp = $twodimarray;
if($current_password eq $passtemp)
{
# print 'ACK';
}
else {
$query= new CGI;
print $query->redirect(-url => 'index_test.shtml');
}


}
}
close(FP);

The client end html page is :

<html>
<script type="text/javascript" src="annotationTools/js/md5.js" ></script>
<body>
<script>
var constantusrname= 'xxx';
var constantpass = 'xxxx';
function onCheck(){

var hash = CryptoJS.MD5(constantpass);
var url = 'session_test.cgi';

// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req_anno = new XMLHttpRequest();
req_anno.open("POST", url, false);
req_anno.send(constantusrname+'&'+hash);
}
else if (window.ActiveXObject) {
req_anno = new ActiveXObject("Microsoft.XMLHTTP");
if (req_anno) {
req_anno.open("POST", url, false);
req_anno.send();
}
}

}

</script>
<input type="button" id = "btnSearch" value = "submit" onclick='onCheck()' />

</body>
</html>

the problem is that when the user press click the page is not being navigated by the cgi on the client browser.

In the firebug the console shows that the index_test.shtml is being get but the user webpage is not redirected it is on the same page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top