Solved

solaris perl using php to output to html with variables

Posted on 2011-09-06
9
231 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now