• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

simple perl ?

Hi,

I have a script to ask a user for a password which works fine if the user types the right password the script will continue.  My problem is I want the script to send the user to a new web page if they type in the correct password how can I do this?
Right now my script just prints out the link.  I want it to execute the link so the user doesn't have to click on the link.  Really it doesn't need to print anything.

Thanks for any help

Here is my script

#!/usr/bin/perl
require "pass-lib.pl";
&Passlib::Login("magic");

print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE>Password Test</TITLE>";
print "</HEAD>";
print 'Okay to goto <A HREF="http://xyz/~paul">Paul\'s Home Page</A>.';


0
onestar
Asked:
onestar
  • 4
  • 4
1 Solution
 
dougisCommented:
this will display the page on the screen for the user however the location will still show the cgi call, is this what you were after?
#!/usr/bin/perl
require "pass-lib.pl";
&Passlib::Login("magic");

print "Content-type: text/html\n\n";
$filepath = "The path to the file you want goes here";
&display_file($filepath);
exit(1);

sub display_file
{
    local ($filename) = @_;
    local ($msgrecs,$rec);
    open(FN,$filename) || die "display_file can't open file $filename";
    @msgrecs=<FN>;
    close(FN);
    foreach $rec (@msgrecs)
    {
         print "$rec";
    }
    return(1);
}
0
 
onestarAuthor Commented:
That is close.  I don't care if it says the location at the top.  Sorry if I miss led you.  I was just saying my script prints something on the screen and then new script doesn't need to output anything to the screen.

The problem with your answer is it works for a file but not for a web page address.  
$filepath = "The path to the file you want goes here";

For example this will not work and this is what I need to work:

$filepath = "http://www.sgi.com";

How can I get this to work?
0
 
dougisCommented:
so you are trying to send the user to a file that is not on your server?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
onestarAuthor Commented:
The file will probably be on my server in this case but in general and for furture reference I would like it to be able to go anywhere.  Even if the file is on my server I still can't type http://myserver/~username
0
 
ozoCommented:
print "Status: 302 Moved\nLocation: http://myserver/~username\n\n";
#instead of
#print "Content-type: text/html\n\n";
#or
use LWP::Simple;
0
 
dougisCommented:
No you can't that is why I said the PATH to the file and not the URL the path would be something like C:\Data\~username\sharedfile.htm
However another way to do this is to use a meta tag

<meta http-equiv="refresh" content="0; url="http://myserver/~username">

so the script looks like this
#!/usr/bin/perl
require "pass-lib.pl";
&Passlib::Login("magic");

print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE>Password Test</TITLE>";
print "<meta http-equiv\=\"refresh\" content\=\"0; url=http://xyz/~paul\">";
print "</HEAD>";
print 'Okay to goto <A HREF="http://xyz/~paul">Paul\'s Home Page</A>.';
This will redirect the browser to the new URL


0
 
onestarAuthor Commented:
dougis your script works fine now thanks
ozo your one line also work fine.
0
 
onestarAuthor Commented:
I would like to give the points for this questions if you would answer it.
0
 
dougisCommented:
Here you go

<meta http-equiv="refresh" content="0; url="http://myserver/~username">

so the script looks like this
#!/usr/bin/perl
require "pass-lib.pl";
&Passlib::Login("magic");

print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE>Password Test</TITLE>";
print "<meta http-equiv\=\"refresh\" content\=\"0; url=http://xyz/~paul\">";
print "</HEAD>";
print 'Okay to goto <A HREF="http://xyz/~paul">Paul\'s Home Page</A>.';
This will redirect the browser to the new URL


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now