Solved

Executing PHP from Perl - source code is displaying

Posted on 2004-08-19
6
270 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 10

Expert Comment

by:eeBlueShadow
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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…

762 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

13 Experts available now in Live!

Get 1:1 Help Now