txp111030
txp111030

Reputation: 305

Perl Redirect CGI File To A "file://" Address

I am a newbie Perl programmer so please go easy on me. Is there any way to remotely redirect a page from calling a perl .cgi file to another page file? The user will click a link which leads to a .cgi file. The .cgi file then will redirect the user to a "file://" location. The purpose is to download a file in another server after logging for click count.

The code below works for "http://" addresses, but how do I get it to work with "file://" addresses?

#!C:\Strawberry\perl\bin

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $page = new CGI;
# print header and start the markup output

print "HTTP/1.0 200 OK\n";
print $page->header( "text/html" );
print $page->start_html( "CGI Environment" );

print "Hello world! ";
print "Press the Enter key to exit.\n";

my $url="file://location_of_file";
my $t=1; # time until redirect activates
print "<META HTTP-EQUIV=refresh CONTENT=\"$t;URL=$url\">\n";


print $page->end_html;

# end code

Is this a good approach? Is there a better approach? Please help. Thank you in advanced!

Upvotes: 0

Views: 189

Answers (2)

tirpitz
tirpitz

Reputation: 1

Probably the most useful way would be by using '.url' files (static or dynamically generated), as explained nicely in JFish222's post

Otherwise, I'm afraid you'd be stuck with elevating privileges (strongly browser dependent), or playing with browser extensions etc..

Upvotes: 0

plasticinsect
plasticinsect

Reputation: 1752

This is not permitted for security reasons. All browsers (that I know of) will refuse a meta redirect from an http:// URL to a file:// URL. The same restriction applies to 30x server redirects. See the Redirect Restrictions section of the Browser Security Handbook for more information.

Upvotes: 2

Related Questions