Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Passing variables from PHP to Perl using passthru()

by cdherold (Monk)
on Jun 15, 2005 at 22:11 UTC ( [id://467085]=perlquestion: print w/replies, xml ) Need Help??

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

Monks,

I am trying to get a variable I have in PHP code to pass through to a perl script. I can execute the perl script from PHP using passthru() or system(), among others, however, I am unclear on how to get the variable from the PHP to be passed and interpreted in the executed Perl script.

I tried

passthru('/home/test.cgi';$var)

but although test.cgi runs, it does not interpret $var. I am not even sure if the placement of $var in the code above is appropriate. I have read the function instructions at php.net, but they did not appear to specify such an option. I only picked it up from searches on google and looking at other pieces of simplistic code.

Most Humbly,

Chris

Replies are listed 'Best First'.
Re: Passing variables from PHP to Perl using passthru()
by BaldPenguin (Friar) on Jun 15, 2005 at 22:28 UTC
    Although this is a PHP question and not a perl:

    The passthru() function allows a second parameter only to store the results of the function call, system() is the same.

    Pass the params inside the call, like
    passthru("/home/test.cgi $var",$result);

    Don
    WHITEPAGES.COM | INC

    Edit by castaway: Closed small tag in signature

      I tried

      passthru("/home/test.cgi $var",$result);

      without success. Is there something that I may have to do to the variable, on exit from php or on entry to perl, to make perl think the variable has been "scrubbed clean" and not subject to tainting by outsiders?

        I was able to duplicate this as written above. Two notes though:

        1) passthru() will work as described above, but the the value stored in the $result will be the exit status of the program. If it is not zero, the program did not run. If it is 127, it could not find the program. As well, passthru() is typically used for binary or raw data: use exec('command','output var','return code') to store the data retrieved form the executed command and system('command','return code') to print string data out as retrieved.

        2) the results of those commands are affected by the INI_SYSTEM values of safe_mode and safe_mode_exec_dir. If safe_mode is set to yes, executable are only allowed in the safe_mode_exec_dir.

        Don
        WHITEPAGES.COM | INC

        Edit by castaway: Closed small tag in signature

Re: Passing variables from PHP to Perl using passthru()
by Xaositect (Friar) on Jun 16, 2005 at 18:58 UTC

    If you're working with PHP and Perl, you may be interested in some of the PHP modules on CPAN like PHP::Session.

    There are actually a suprising number of Perl modules for working with PHP.


    Xaositect - Whitepages.com
Re: Passing variables from PHP to Perl using passthru()
by chanio (Priest) on Jun 17, 2005 at 04:48 UTC
    Hi,

    Use the following to insert the output of a calling to a perl.cgi (just as any other cgi-bin calling) directly into an HTML page...

    <?php global $host; $host=empty($_SERVER['HTTP_HOST'])? 'http://'.$HTTP_SERVER_VARS['HTTP_ +HOST']:'http://'.$_SERVER['HTTP_HOST']; ; include($host."/cgi-bin/fortune.cgi?add") ; //php calls Perl cgi & lo +ads JS vars ?>
    And do the following to get your resulting values (allways in an array) from a simple command line call to a perl script:
    <?php $command='perl d:\xampp\htdocs\modperl\riset.pl'; $array = exec($command); list($rises,$sets,$tmoon)=explode("|",$array); ?>
    This should help.Should this be another snippet? Nah, it's PHP!

    .{\('v')/}   C H E E R   U P !
     _`(___)' ___a_l_b_e_r_t_o_________
    
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found