Solved

solaris perl using php to output to html with variables

Posted on 2011-09-06
9
249 Views
Last Modified: 2012-05-12
I am using perl to execute a php script to convert to html.  I have no problem in converting php to html when there are no variables used in the php statement, but when I attempt to add a variable to the php file, I get an error.
Below is the perl code snippet:
$myurl="build_report.php?customer=ACME";
system(`cd /var/opt/webstack/apache2/2.2/htdocs/customers/; \
 /opt/webstack/php/5.2/bin/php $myurl >/tmp/mytest.html`);

on executing the code, I get the following error:
Could no open input file: build_report.php?customer=ACME

I have tried using quotes around 'ACME', but same results.  When I do the same script with a php file that does not require the variable "customer", everything works as planned.

Any ideas on how to pass a php variable to the php script from within perl?
0
Comment
Question by:bray007
  • 5
  • 3
9 Comments
 

Author Comment

by:bray007
ID: 36493491
ultimately, I'll probably want to add multiple php variables to the statement.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 36493521
The issue is not that you are calling the php script from perl, it is that the php script was designed to be invoked as a script on a web site, and uses CGI to get its arguments.

If you are lucky, it was also programmed to take command line arguments.  If so, the command line might look something like this:

$myurl="build_report.php customer=ACME";

Open in new window

0
 

Author Comment

by:bray007
ID: 36493537
I have the php script setup for a $_GET, I've also tried $_POST

when I make the changes suggested, I get:
PHP Notice: Undefined index: statuscode in /var/blah blah on line 33
PHP Notice: Undefined index: customer in /var blah blah on line 34.

any thoughts on what I would need to change?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

Expert Comment

by:sjklein42
ID: 36493566
It may help to know that you can pick up command line arguments using the $_SERVER array.

0
 

Author Comment

by:bray007
ID: 36493601
I'll try that avenue.  If you have a sample script for PHP where I can get it to return the argument in the php, I would appreciate it and reward the points.

Thanks for your help.
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 36493649
The most basic way to get to the command line is through "argc" and "argv".

See http://en.wikipedia.org/wiki/Command-line_argument_parsing#PHP

PHP uses argc as a count of arguments and argv as an array containing the values of the arguments.

There are any number of ways to do it, but the most "standard" is to create an array ($args) from command-line arguments in the -foo:bar format, like this:


$args = parseArgs( $argv );
echo getArg( $args, 'customer' );
 
function parseArgs( $args ) {
        foreach( $args as $arg ) {
                $tmp = explode( ':', $arg, 2 );
                if( $arg[0] == "-" ) {
                        $args[ substr( $tmp[0], 1 ) ] = $tmp[1];
                }
        }
        return $args;
}
 
function getArg( $args, $arg ) {
        if( isset( $args[$arg] ) ) {
                return $args[$arg];
        }
        return false;
}

Open in new window


Then, when you call it, remember to use the "-" before the word customer

 $myurl="build_report.php -customer:ACME"; 

Open in new window


Let me know if you need more.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 36495990
Why are you using a backticks statement inside the system call?  If you want to capture the output of the command, then use backticks or the qx operator.  If you don't need to capture the command's output in Perl, then use the system function or open a pipe.

Another option you might want to look at is to use the PHP::Interpreter module instead of the system call.  The module makes it easy to pass the needed POST/GET data.

http://search.cpan.org/~aff/PHP-Interpreter-1.0.2/lib/PHP/Interpreter.pm
0
 

Author Comment

by:bray007
ID: 36585194
i am still have some issues on this, but I believe the original responder pointed me in the right direction to resolve the issue.  Full points will be awarded.  
Thank you!!
0
 

Author Closing Comment

by:bray007
ID: 36585199
great help in pointing me to the proper direction to finish the task.  Thanks.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySql and Apache/PHP Error Reporting 2 28
website maintenance mode 1 17
Cookie not unsetting 7 19
perl syntax 3 4
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question