rene.n has asked for the wisdom of the Perl Monks concerning the following question:

How can I pass the value of engr from a PHP script to a PERL. Below is the PHP script.
$user = getenv("REMOTE_USER"); $db = mysql_connect("localhost", "user", "password"); mysql_select_db("db", $db); $result = mysql_query("SELECT * FROM tablename WHERE username = ' +$user'"); $engr = mysql_result($result,0,"engr"); $team = mysql_result($result,0,"team_name"); $position = mysql_result($result,0,"team_position"); $group = mysql_result($result,0,"grp"); $level = mysql_result($result,0,"level");

edited: Wed Sep 18 03:58:42 2002 by jeffa - code tags

Replies are listed 'Best First'.
Re: Getting a value from a PHP script
by kabel (Chaplain) on Sep 18, 2002 at 05:55 UTC
    you could for example open a new process with the popen call:
    $fp = popen ("perl -w really-dont-know-if-this-works.pl", "w");
    there are at least two possibilities to pass a value to that new process: via STDIN or via command line (then a system () call would suffice).

    note that this "solutions" are NOT beautiful, in fact i suggest to forget them.
Re: Getting a value from a PHP script
by jens (Pilgrim) on Sep 18, 2002 at 05:12 UTC
    Since it's not a very large script, why not simply re-write it in Perl, using the DBI.pm and CGI.pm modules?

    Microsoft delendum est.
Re: Getting a value from a PHP script
by blm (Hermit) on Sep 18, 2002 at 11:46 UTC
    In processing the form submission can you foward the user from the php script to a url of a perl cgi script with engr as a parameter? You want them to go to a url like http://mysite/myperlscript?engr=somevalue. I am not sure how to do this in PHP.

    In the perl script have something like this to get the parameter into a scalar and do something with it.
    use CGI; my $cgi = new CGI; ... my $engr_value = $cgi->param("engr"); #Do something with based on the value of $engr_value

    Of course you will have to take into account the fact that the script will run under reduced privileges similar to the web server. This would be the same with the other suggestions made.

Re: Getting a value from a PHP script
by thunders (Priest) on Sep 18, 2002 at 13:37 UTC
    To achieve the same thing in perl (and in keeping with a similar layout to your code) try something like this:
    use DBI; use strict; my $user = $ENV{REMOTE_USER}; my $driver = 'mysql'; my $database = 'db'; my $dsn = "DBI:$driver:database=$database"; my $dbh = DBI->connect($dsn, 'user', 'password') or die $DBI::errstr; my $result = $dbh->prepare("SELECT * FROM tablename WHERE username =?" +); $result->execute($user); my $row = $result->fetchrow_hashref; my $engr = $row->{engr}; my $team = $row->{team_name}; my $position = $row->{team_position}; my $group = $row->{grp}; my $level = $row->{level}; $result->finish; $dbh->disconnect;

    update: corrected a few missing mys

Re: Getting a value from a PHP script
by Aristotle (Chancellor) on Sep 18, 2002 at 18:15 UTC
    $result   = mysql_query("SELECT * FROM tablename WHERE username = '$user'"); You have an SQL injection vulnerability there.

    Makeshifts last the longest.

      You have an SQL injection vulnerability there.

      Forgive my ignorance, but what is an "SQL injection vulnerability"?

      --
      Microsoft delendum est.

        you'll notice in the code sample i provided i threw in a quesion mark. that is a place holder, a way of ensuring proper quoting with DBI. I'm not sure how PHP implements this. if someone were to spoof their REMOTE_USER string to report
         bill' OR 'cracked'='cracked

        you suddenly have a breach where all the data in that table is pulled in.