Solved

Executing PHP from Perl - source code is displaying

Posted on 2004-08-19
6
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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