0

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!

txp111030
  • 305
  • 1
  • 4
  • 11
  • If the file is on a server, file:// won't be able to get out anyway, or are you talking about a network share when you say server? – ikegami Apr 17 '15 at 04:58

2 Answers2

2

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.

plasticinsect
  • 1,702
  • 1
  • 13
  • 23
  • Is there a way to call a "file://" url from Perl? – txp111030 Apr 17 '15 at 03:13
  • 3
    If you want to open a file local to the server than just use `open`. If you want to open a file on the client, then no. For me it looks like you don't understand the concepts how the web works, which has nothing to do with Perl. – Steffen Ullrich Apr 17 '15 at 04:29
0

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..

Community
  • 1
  • 1
tirpitz
  • 1
  • 1