Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Can't Get CGI Results Page to Redirect

by socrtwo (Sexton)
on Aug 03, 2009 at 20:11 UTC ( #785543=perlquestion: print w/ replies, xml ) Need Help??
socrtwo has asked for the wisdom of the Perl Monks concerning the following question:

Hi. Sorry for the confusing English...,

My father is a stamp dealer for French or Chinese stamps. I am trying to create a stamp ID Web service using ImgSeek, where a user can upload an image of a French or Chinese stamp and then get back 10 or so images from a collection of 3,250 scanned images that are most similar in color and image shape. The image names are attached to the images and since the image names contain the Scott Catalog Number, the stamp can be possibly identified.

I realize there are copyright issues with the Scott Catalog's publisher, an issue which I would rather not discuss here. I'm using this only as test case. I'm wishing to create a broader uploaded image ID system for release as open source after later switching to an open source uploader and adding a GIF, JPEG and PNG to BMP converter module.

I have presently modified a commercial freeware CGI uploader script from perlservices. I have added code from a Japanese site here, that catalogs each uploaded BMP image using the Perl Module wrapper of ImgSeek, Image::Seek.

The cataloging works pretty well seemingly easily detecting if I have already uploaded a BMP image, and not adding it to the imgname and imgseek databases specified in the code named "" on the Japanese site.

On that site there is also a CGI script called "seek.cgi" which will return the images most similar to the one whose database number key is added either to the form with it's naked URL or added to the returned results CGI page, where the form exists again for further entry.

Since the '' code returns the newly uploaded image's newly created imgname.db and imgseek.db number keys, with regular expressions, I'm able to isolate the new key and construct the URL of the seek.cgi query which I would like to make, which is that of the newly uploaded image. For instance:

So, here's the rub, I can get my uploader CGI results to print my constructed URL for the uploaded image, but I can't the browser to redirect to the new page. I have tried to put this code from the Perl Cookbook in the header section of the upload script:

$url = "$"; print "Location: $url\n\n"; exit;

I have Jail Shell access, and was able to check that the was not running through successfully when the header was executing, suggesting that the file had not uploaded yet when the header was writing...I guess. This was true, even if I made my script sleep. So here is that code:

`perl > testout.txt`; sleep 1 while ( !(-e "testout.txt") ); use File::Copy; copy("testout.txt", "testout2.txt") or die "File cannot be copied."; $file = "testout.txt"; unlink($file); { local $/=undef; open FILE, "testout2.txt" or die "Couldn't open file: $!"; binmode FILE; $content = <FILE>; close FILE; } # URL that generated this code: #[3418]./img10_small.bmp&7 $txt=$content; $re1='.*?'; # Non-greedy match on filler $re2='(\\d+)'; # Integer Number 1 $re=$re1.$re2; if ($txt =~ m/$re/is) { $int1=$1; print "$int1 +"; } #----- # Paste the code into a new perl file. Then in Unix: # $ perl #-----

I also tried putting this first method from the Cookbook, after everything but the footer printed. Then I tried redirecting from inside the footer too. None of these methods would execute a redirection.

So I tried the second Perl Cookbook method:

my $url = $; # See the code j +ust above print redirect( -URL => $url);

I tried this code too, in the header, in the middle of the script and in the redirection. In the footer I tried putting the statement before printing </body>, and I also tried putting it after printing just </body>

print qq~</body>~; blahblahcode; print qq~</html>~;

From my cPanel X account, I also tried installing and then using CGI::Application::Plugin::Redirect;, with this code

sub PrintHead { print qq~Content-type: text/html\n\n~; BEGIN { my $homedir = ( getpwuid($>) )[7]; my @user_include; foreach my $path (@INC) { if ( -d $homedir . '/perl' . $path ) { push @user_include, $homedir . '/perl' . $path; } } unshift @INC, @user_include; } use CGI::Application::Plugin::Redirect; sub byebye { my $self = shift; return $self->redirect(" +/seek.cgi?id=2225", '301 Moved Permanently'); # Just trying to get an + example working... } print qq~ <html> <title> Free upload utility</title> <body bgcolor="#ffffff"> ~; }

Nothing happens from the header, my results page is returned per normal (from my last project). cPanel makes you put in the 'include' code that's at the beginning if that is confusing you. It allows the module work. I tested the module with Jail Shell to make sure it was not producing an error and it did not return an error.

I tried several permutations not mentioned here, also without success. Why is it so difficult to get a redirection?

Comment on Can't Get CGI Results Page to Redirect
Select or Download Code
Re: Can't Get CGI Results Page to Redirect
by thezip (Vicar) on Aug 03, 2009 at 20:30 UTC


      Yeah I hard coded the redirection and no redirecting occurred.




Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://785543]
Approved by broomduster
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-11 10:30 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (224 votes), past polls