Click to See Complete Forum and Search --> : passing vars from Perl to PHP -help!
CurrentWave
06-03-2003, 04:56 PM
I need to gab some variables from a Perl 5 file before they are gone.
First, I need to know how to call another file from a Perl file, and second, how to pass the vars from the Perl file to the second file (PHP) for my use.
And, last of all, can anyone tell me if any thing is wrong with the following Perl, its not working -
## creats an unique name for the write file
$t = &getTime();
$d = &getDate();
$d =~ s/\//_/g; # get rid of forward slash
$d =~ s/^\s+//; #Trim leading white space
$d =~ s/\s+$//; #Trim trailing whitespace
$d =~ s/\s/_/g; #Trim other whitespace, replace with underscore
$t =~ s/:/_/g;
$id = 'x' . $d . $t . '.txt';
#create an unique file and open for writing
open(PERLOUTFILE, ">$id");
print PERLOUTFILE $OrderID, "\t"
print PERLOUTFILE $Success, "\t";
print PERLOUTFILE $Name, "\t"
print PERLOUTFILE $Street, "\t"
print PERLOUTFILE $City, "\t"
print PERLOUTFILE $State, "\t"
print PERLOUTFILE $Zip, "\t"
print PERLOUTFILE $Country, "\t"
print PERLOUTFILE $Email, "\t";
print PERLOUTFILE $Total, "\t";
print PERLOUTFILE "\n";
close(PERLOUTFILE);
exec "/www.domain/cgi-bin/transactions.php" $id;
Thank you for the Perl assist!
Jami
jeffmott
06-03-2003, 06:07 PM
I've posted a reply to your post in the PHP forum, but I think I understand better of what you need here. If a small set of scalar variables is all you need to to pass then you could perform a redirect at the end of your Perl script to your PHP file with the variables in the query string.use CGI;
use URI::Escape;
my $cgi = CGI->new();
.
.
.
our $save_this_var = 'hello';
our $this_one_too = 'world';
my $qs;
{
no strict 'refs';
$qs = join(';', map { uri_escape($_) . '=' . uri_escape($$_) } qw{save_this_var this_one_too});
}
print $cgi->redirect("http://www.site.com/page.php?$qs");## creats an unique name for the write file
$t = &getTime();
$d = &getDate();This will only work [most of the time] if you anticipate few visitors. There is every possibility that two instances of the script may be called at the same time. Better to store an ID# in some kind of database that can be locked while the ID# is retrieved and incremented. Do some research on "race condition" for more information on this type of problem.print PERLOUTFILE $OrderID, "\t"Missing a semi-colon here.exec "/www.domain/cgi-bin/transactions.php" $id;Since a PHP file is not an executable program strictly speaking, this will most likely return an error. It needs to be called through the Web server. See the Perl redirect above.
CurrentWave
06-05-2003, 05:40 PM
But I'm afaid your going to have to spell it out for me :-)
Now because the following:
$Success = "$MYVARS{'Status'}";
$OrderID = "$MYVARS{'OrderID'}";
$Name = "$MYVARS{'NameonCard'}";
$Street = "$MYVARS{'Cardstreet'}";
$City = "$MYVARS{'Cardcity'}";
$State = "$MYVARS{'Cardstate'}";
$Zip = "$MYVARS{'Cardzip'}";
$Country = "$MYVARS{'Cardcountry'}";
$Email = "$MYVARS{'email'}";
$Total = "$MYVARS{'total'}";
is already in the Perl file, all I need to do is to remove this:
our $save_this_var = 'hello';
our $this_one_too = 'world';
from your script, and change this:
uri_escape($$_) } qw{$Success $OrderID $Name $etc});
}
like so.... -yes?
print $cgi->redirect("www/account/page.php?$qs");
I leave everything else the same -yes?
And then I can use $Success, etc. in my PHP -yes?
I agree with you about the creating and posting to a file, it could be a problem. I never wanted to do it that way, but that was the only suggestion I could fine at the time.
Thanks for all your help Jeff!
jeffmott
06-05-2003, 08:05 PM
qw{$Success $OrderID $Name $etc}This should be a list of only the name of the variable. e.g.,qw{Success OrderID Name}Also, each varialbe meant to be saved in this manner will have to be delcared with the our keyword if strict in enabled (which it should be, by the way).print $cgi->redirect("www/account/page.php?$qs");This should be an absolute URI. e.g., http://www.site.com/account/page.php?$qsAnd then I can use $Success, etc. in my PHP -yes?You can get at the value with $_GET['Success'] (I believe anyway, I don't usually work in PHP)
CurrentWave
06-05-2003, 10:27 PM
Okay I get the first part - remove the $, but then I am stuck again.
So how do I use this:
our $save_this_var = 'hello';
When my data is already in the form $Var
Do I do this...
our $Success = 'Status';
And if so, will it cause any problems with these already assigned in the top of the script -
$Success = "$MYVARS{'Status'}";
$OrderID = "$MYVARS{'OrderID'}";
$Name = "$MYVARS{'NameonCard'}";
As for the absolute URI - my host says to use my account path which goes like this -
www/gcm/garycarpenter/cgi-bin/file.exe
Not a URL that would come from the outside - does this make sense?
Thanks for explaining it to me.
Jami
jeffmott
06-05-2003, 11:11 PM
And if so, will it cause any problems with these already assigned in the top of the scriptIf they are already defined then there is no need to do so again. The declarations you have setup already will be sufficient.As for the absolute URI - my host says to use my account path which goes like this -
www/gcm/garycarpenter/cgi-bin/file.exe
Not a URL that would come from the outsideWell, the HTTP specification and CGI.pm documentation say otherwise.