Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Changing the location header when a port and form data are envolved.

by akm2 (Scribe)
on Aug 06, 2001 at 19:08 UTC ( [id://102476]=perlquestion: print w/replies, xml ) Need Help??

akm2 has asked for the wisdom of the Perl Monks concerning the following question:

The code below is some simple code I wrote that works fine except for the print "location: http://www.mscorp.org:3380/connect.asp?Server=www.mscorp.org&rW=640&rH=480&\n\n"; line. Can somebody show me how to connect the user to that location after my script has run?

#!/usr/bin/perl #Get the requested application ID. $requestedApp = $ENV{'QUERY_STRING'}; #List Application IDs & executable path for the application ID. %apps qw( USA C:\Apps\USA\USA.EXE ); #Match $requestedApp to an executable path. foreach $appkey (keys(%apps)){ if ($appkey eq $requestedApp){ $requestedAppPath = $apps{$appkey}; break; } } #Write entry to logfile. open(DBFILE,">>/usr/local/apache/post/www/tsweb.log"); print DBFILE "$ENV{'REMOTE_ADDR'}|$requestedApp|$requestedAppPath| +\n"; close(DBFILE); #Connect the user to the Application Server and terminate the script. print "location: http://www.mscorp.org:3380/connect.asp?Server=www.msc +orp.org&rW=640&rH=480&\n\n"; exit;

Replies are listed 'Best First'.
Re: Changing the location header when a port and form data are envolved.
by maverick (Curate) on Aug 06, 2001 at 19:20 UTC
    You should really consider using CGI.pm since it does 90% of what you are doing here. But at first glance, I think 'location' has to be 'Location'.

    /\/\averick

Re: Changing the location header when a port and form data are envolved.
by abstracts (Hermit) on Aug 06, 2001 at 22:00 UTC
    Hello

    This is just a comment about this clock. You are thinking way too much while you should be reading the documents (perldoc perldata now). You will see that this block:

    #Match $requestedApp to an executable path. foreach $appkey (keys(%apps)){ if ($appkey eq $requestedApp){ $requestedAppPath = $apps{$appkey}; break; } }
    should be replaced by:$requestedAppPath = $apps{$requestedApp}; You rarely need to iterate over hash keys.

    Hope this helps,,,

    Aziz,,, Update: Your code has a missing assignment "=" also:

    %apps = qw(
        USA C:\Apps\USA\USA.EXE
    );
    
Re: Changing the location header when a port and form data are envolved.
by little (Curate) on Aug 07, 2001 at 14:02 UTC
    Adding upon what others said before: USE CGI.pm
    Doing so enables you to quickly issue a redirection header by :
    print $cgiObject->redirect($targetUrl);

    But CGI.pm does also allow to be used as a library of functions also. So you might want to read the docs :-)
    Regarding a redirection header your print statement should look alike:
    print "Status: 302 Moved\nLocation: http://www.mscorp.org:3380/connect +.asp?Server=www.mscorp.org&rW=640&rH=480&\n\n";

    Have a nice day
    All decision is left to your taste

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://102476]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-28 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found