Solved

Executing PHP from Perl - source code is displaying

Posted on 2004-08-19
6
273 Views
Last Modified: 2008-03-17
Hi,

Here's what is happening:

I have a php script which runs fine from the command line, and via the web.  I'd like to call the script from a perl cgi, to get the results (it's ugly, but would be a simple solution to our problem) of it.  

What happens is very strange.  At the point where the php script is supposed to execute, basically, the entire contents of the script are printed out (the script didn't execute) and the perl script seems to bomb out as well.  So on the web page, i see the entire source code to the php script, and also some code from the perl script.  It's really bizarre.

Any ideas on what is causing this?  I'm fairly experienced at perl, cgi, etc., and have tried many tricks to see what might work.  

-Jim
0
Comment
Question by:jimr390
  • 3
  • 2
6 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 11846201
can you give an example how your are calling the php-script from perl ??
The following gives me the output of the execute php-script not the source-code

perl -e 'print `php /php/version.php`'
0
 

Author Comment

by:jimr390
ID: 11846772

Ok, the script runs fine from the command line as you show (perl -e 'print `php /php/version.php`')

The problem is running it through the browser as a cgi, then the php callout (using `` or open, doesn't matter) shows source code.

0
 
LVL 48

Accepted Solution

by:
hernst42 earned 200 total points
ID: 11849270
The followoing perl-script works for me (don't know if you need to include all those modules):

#!/usr/bin/perl
use CGI::Carp qw(carpout fatalsToBrowser);
use cgiadapt;
use security;

print qq~Content-Type: text/html

~;

print `/usr/bin/php /php/version.php`;

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 11852725
If you are using open in perl, then you are simply opening the php file (for example like you would in a text editor) and all you will get is the contents.

if you use the command
    print `php /php/version.php`
in your CGI page that should work as you expect
0
 

Author Comment

by:jimr390
ID: 11853341
Well, actually, I was doing an open with a |, which should execute the code and give me stdout.

Anyway, as it turns out, we are abandoning our approach and taking a different tact.  So, the point is moot.

I'll close this out and divide up the points to those who responded - thanks for trying to help.

-Jim
0
 
LVL 48

Expert Comment

by:hernst42
ID: 11853568
you may give us the example how you are doing the exec within perl, so we can see what the problem may be with your code.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

830 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