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

hi there. I am looking for some info how to transfer operation result from one perl cgi to another cgi - a simple text string e.g "john.big" wchich is the name of file processed by CGI no.1 ($johnbig) and needs to be put in CGI no.2 as $john. the problem is that cgi 1 and 2 are working for multiusers and I do not want to share this info - $johnbig & $john needs to be strict value for each session and will be different for each user. I need simple solution - like button - "auto copy and paste" or similar. cgi 1 will wait until cgi 2 sends the data string. Thnx for help

Replies are listed 'Best First'.
Re: transfer data between 2 perl progs
by Thilosophy (Curate) on Dec 15, 2004 at 12:04 UTC
    Not sure exactly what you mean, but there are basically two ways:

    a) You can use LWP to have one CGI read the output of the other CGI. Note that the user's browser (and his session cookies and these things) are not involved here, so if you need some session data, you need to explicitly pass it from the first CGI (accessed by the user) to the second CGI (accessed by your server) somehow.

    b) If you want the user (his browser) to be transfered from one CGI to the next, you can use HTTP redirects. You can include additional parameters in the redirect URL. If you need to do a POST request, you can print out an HTML form and have the user press a button to go to the next CGI ( with the option to press the button automatically by JavaScript)

    In both cases, you have to be aware that everything a CGI gets as input can potentially be tampered with by the user.

Re: transfer data between 2 perl progs
by EverLast (Scribe) on Dec 15, 2004 at 11:56 UTC
    I don't quite get it - are you redirecting from CGI 1 to CGI 2?

    If so, just pass the arguments to CGI 2. use HTTP_METHOD (or arguments) to determine whether you are on the initial read or subsequent post.

    If not - how are 'CGI 1 & 2' connecting?

    ---Lars

    Update: Regarding session data and tampering, see my note in the Storing encrypted data in url thread.

      thnx first cgi is processing big database for several users, also provide data entry forms based on http interface, second cgi is for file upload to the server (file renaming, viruses check etc.) so when cgi 1 is ready for data entry (generated html page) one of the fields is a link to the file upload cgi. I can't get this cgi working under sub of cgi1 because of several reasons which are not important here. When CGI 2 has uploaded and renamed the file with success it is generating info page about this success to inform the user. And here I need to copy a new name of the file (eg. $end_name of cgi2) as a hidden process into CGI1 as a variable (eg. $file_name). I do not know how to make possible this operation to be done on the client computer without server involving in it. (it maybe 100 separated sessions of this cgi programs at the time) I have never done data transfer between 2 separated cgi, I do not want make possible to track down the server paths where this file is going to be stored and what name it got renamed with. So please describe the best way to do it because I am beginner with it. I am looking for this info on the net but without any results. I can't open the cgi 2 under cgi 1 with any links like /a href=$ENV{blah blah blah}/ or /form .../ because it has a separate interface. So I am looking for possibility to copy $end_name (cgi2) to memory and paste it to $file_name (cgi1) from memory. big thnx for any help. Mark