in reply to Re^2: data persistence
in thread data persistence

If you insist...
You have to identify the requester, and the only way you seem to have is the env REMOTE_ADDR.
Note that you cannot always trust this value since users behind proxies will have the same IPs.

So, on every request, instead of recreating the temp file, use append if the record for the IP is not present. Make sure you treat concurrent access to the file.
Another way is to create a file for each IP that hits your server.

Replies are listed 'Best First'.
Re^4: data persistence
by need_help21 (Novice) on Dec 13, 2007 at 13:18 UTC
    #! /usr/bin/perl -w #!/usr/bin/speedy -w -- -t600 use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; use Net::Telnet; use Net::FTP; use JavaScript::Writer; use JavaScript::Writer::Function; use File::Listing qw(parse_dir); use CGI::Auth; use CGI::Session; use Win32; #use File::Temp; my $htm = new CGI; my $cgi = new CGI; my %vars = $htm->Vars(); print $htm->header({ -type => "text/html"}); print $htm->start_html( -title => "Welcome", -style=>{'src'=>'../stdbstyle.css'}); my $rep; if(defined($vars{'submit'}) and $vars{'submit'} eq 'Submit') { fnSaveFile(); }elsif(defined($vars{'execute'}) and $vars{'execute'} eq 'Execute') { fnExecFile(); }#elsif(defined($vars{'FTP'}) and $vars{'FTP'} eq 'FTP') { # fnFTPfiles(); #} elsif(defined($vars{'GET'}) and $vars{'GET'} eq 'Report') { &fnGetReport($rep); }elsif(defined($vars{'ShortReport'}) and $vars{'ShortReport'} eq 'Shor +t report') { &fnShortReport($rep); }elsif(defined($vars{'file_creation'}) and $vars{'file_creation'} eq ' +FILE CREATION N EXECUTION') { fnShowFileCreationForm(); }elsif(defined($vars{'file_execution'}) and $vars{'file_execution'} eq + 'SHELL FILE EXECUTION') { fnShowFormForExecution(); }elsif(defined($vars{'get_report'}) and $vars{'get_report'} eq 'GETTIN +G THE REPORTS') { fnShowFormForGettingReport(); }#elsif(defined($vars{'submit_login'}) and $vars{'submit_login'} eq 'S +end') { # fnSubmitLogin(); #} else { #fnShowFileCreationForm(); fnShowMainMenu(); #fnLoginForm(); } #----------------------------- sub fnGetReport { my $sReport = $vars{'report'}; if ($sReport eq '') { if (-e "temp") { open(DAT, "temp"); $sReport = <DAT>; close DAT; if ($sReport eq 'Empty') { fnShowFormForGettingReport(); print "Please provide the name of the Report file" +; exit(); } } }else { open(FILE,">temp") or die "Can not open file temp"; print FILE "$sReport"; flock FILE, 2; #close FILE; } } #---------------------------- sub fnShortReport { our $username; our $password; my $sReport; print "Report=$sReport"; $username = $raw_data[0]; $password = $raw_data[1]; close DAT; my $sReport = $vars{'report'}; if ($sReport eq '') { if (-e "temp") { open(DAT, "temp"); $sReport = <DAT>; close DAT; if ($sReport eq 'Empty') { fnShowFormForGettingReport(); print "Please provide the name of the Report file"; exit(); } } }else { open(FILE,">temp") or die "Can not open file temp"; print FILE "$sReport"; close FILE; }
      need_help21,

      You need to make some effort, you have just posted some code, with no description of any problems you are having. Help us to help you. Are you using all of these modules? You have use CGI::Session; but never use it. Did you see the messages use strict; reports about @raw_data? Do you intend to have everone use the same file "temp"? Perhaps you should read How do I post a question effectively?. You still have not told us why using Cookies/Sessions "does not work".

      Hope this helps

      Martin
      You are still using the same filename for all requests.
      Instead of 'temp', give each request a file of their own.
      my $filename = join('', split('\.', $ENV{REMOTE_ADDR}) ); ... # then, somewhere write to / read from the file
      And because that may lead to a huge list of filenames, consider building a tree of directories based on the first numbers of the IP.
      my @numbers = split('\.', $ENV{REMOTE_ADDR}); if( ! -d $numbers[0] ) { mkdir($numbers[0]); } if( ! -d "$numbers[0]/$numbers[1]" ) { mkdir("$numbers[0]/$numbers[1]"); } my $path = "$numbers[0]/$numbers[1]"; my $filename = "$path/" . join('', @numbers);