For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > February 2005 > Perl out to PHP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl out to PHP
Ing. Branislav Gerzo

2005-02-03, 3:55 pm

Hi all,

My friend is making website in PHP, but my scripts are in Perl, for
example user write some text, and I want for example print it
uppercase (I know, bad example, but I want/have to do it - something
different and more complex - in my case via Perl).
So I'm thinking how to do it best.

Scenario looks like:

1. user comes to website (PHP), fill in text-area, click SEND button to
cgi-bin/uppercase.cgi
2. on my server in uppercase.cgi all text change to uppercase and this
result I want send back via _PHP_ to user.

Thanks for any help and examples.

--

--. ,-- ,- ICQ: 7552083 \|||/ `//EB: www.2ge.us
,--' | - |-- IRC: [2ge] (. .) ,\\SN: 2ge!2ge_us
`====+==+=+===~ ~=============-o00-(_)-00o-================~
Orville's mind is like a steel trap - rusted shut!




Paul Archer

2005-02-03, 3:55 pm

4:19pm, Ing. Branislav Gerzo wrote:

> Hi all,
>
> My friend is making website in PHP, but my scripts are in Perl, for
> example user write some text, and I want for example print it
> uppercase (I know, bad example, but I want/have to do it - something
> different and more complex - in my case via Perl).
> So I'm thinking how to do it best.
>
> Scenario looks like:
>
> 1. user comes to website (PHP), fill in text-area, click SEND button to
> cgi-bin/uppercase.cgi


No problem. The whole point of CGI is to not have to worry about what a
program/script is written in.


> 2. on my server in uppercase.cgi all text change to uppercase and this
> result I want send back via _PHP_ to user.
>

Um, wouldn't it be a lot better if you sent back the results using HTML?
Gary Stainburn

2005-02-04, 3:55 pm

On Thursday 03 February 2005 6:50 pm, Paul Archer wrote:
> 4:19pm, Ing. Branislav Gerzo wrote:
>
> No problem. The whole point of CGI is to not have to worry about what
> a program/script is written in.
>
>
> Um, wouldn't it be a lot better if you sent back the results using
> HTML?


I think he means that he wants his perl to generate HTML containing PHP.

The problem here is that it won't get processed by the PHP engine.

The two simplest choices are 1) generate all the HTML within your perl,
or 2) generate a redirect within your perl to an existing file that
contains the PHP.

--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Thomas Bätzler

2005-02-04, 3:55 pm

Ing. Branislav Gerzo <konfera@2ge.us> asked:
> 2. on my server in uppercase.cgi all text change to uppercase and this
> result I want send back via _PHP_ to user.


Theoretically it should suffice to make sure that your
output has the proper MIME type for a PHP document, i.e.
"application/x-httpd-php".

Practically, things could be a bit more complicated.
What you want to do is run one document through two
request handlers - cgi and php - in turn. This will
not work in apache 1.3. It may work in apache 2.x,
but may require special confifiguration. As for other
web servers, I don't even want to speculate.

HTH,
Thomas
Paul Archer

2005-02-04, 3:55 pm

8:20am, Gary Stainburn wrote:

> On Thursday 03 February 2005 6:50 pm, Paul Archer wrote:
>
> I think he means that he wants his perl to generate HTML containing PHP.
>

Understood. My point was more along the lines of: "What do you really want
to do, and why don't you state that clearly, instead of making us
mind-read?"


Ing. Branislav Gerzo

2005-02-04, 3:55 pm

Paul Archer [PA], on Friday, February 4, 2005 at 08:14 (-0600 (CST))
thinks about :
[color=darkred]

PA> Understood. My point was more along the lines of: "What do you really want
PA> to do, and why don't you state that clearly, instead of making us
PA> mind-read?"

ok, sorry then. We have website done with PHP, it did my brother. But
I'm more into perl, so I did some scripts. Website is about checking
IPs (if it is up, and so on), so I wrote script for that. Ok, now my
problem:

user come to website, write in textbox some IPs, I want send this
input to my perl script (parse that text, takes IPs, do operation with them -
insert them to database, check them...), and send results via _PHP_ to
user.

Thanks to all for replies!

--

...m8s, cu l8r, Brano.

["Bother!" said Pooh, as Piglet sacrificed him to the dark gods.]


Gary Stainburn

2005-02-04, 3:55 pm

On Friday 04 February 2005 2:23 pm, Ing. Branislav Gerzo wrote:
> Paul Archer [PA], on Friday, February 4, 2005 at 08:14 (-0600 (CST))
>
> thinks about :
>
> PA> Understood. My point was more along the lines of: "What do you
> really want PA> to do, and why don't you state that clearly, instead
> of making us PA> mind-read?"
>
> ok, sorry then. We have website done with PHP, it did my brother. But
> I'm more into perl, so I did some scripts. Website is about checking
> IPs (if it is up, and so on), so I wrote script for that. Ok, now my
> problem:
>
> user come to website, write in textbox some IPs, I want send this
> input to my perl script (parse that text, takes IPs, do operation
> with them - insert them to database, check them...), and send results
> via _PHP_ to user.
>
> Thanks to all for replies!


Okay, so you've got the perl script to generate a response to the ping
but you want the PHP engine to format the resulting HTML page?

Back to my original answers

1) convert the PHP to perl and get perl to generate the final HTML page
2) have the perl CGI perform the required task and store the result
somewhere, then generate a HTTP redirector pointing to a PHP page which
reads that response from wherever it was stored.
--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Brad Lhotsky

2005-02-04, 3:55 pm

On Fri, Feb 04, 2005 at 03:23:49PM +0100, Ing. Branislav Gerzo wrote:
> Paul Archer [PA], on Friday, February 4, 2005 at 08:14 (-0600 (CST))
> thinks about :
>
>
> PA> Understood. My point was more along the lines of: "What do you really want
> PA> to do, and why don't you state that clearly, instead of making us
> PA> mind-read?"
>
> ok, sorry then. We have website done with PHP, it did my brother. But
> I'm more into perl, so I did some scripts. Website is about checking
> IPs (if it is up, and so on), so I wrote script for that. Ok, now my
> problem:
>
> user come to website, write in textbox some IPs, I want send this
> input to my perl script (parse that text, takes IPs, do operation with them -
> insert them to database, check them...), and send results via _PHP_ to
> user.


I think you're misunderstanding. PHP and Perl are both server side
technologies in this particular situation. They BOTH generate HTML
which is your client side interface. Regardless which you use, the
client is none-the-wiser, nor should it matter.

The "user" doesn't know or care about PHP. As far as your browser is
concerned .php is just another ".html" extension. Don't believe me?
"View Source" on a perl generated and php generated page and show me
where you see your code that generated that page.

Let me take a second to explain what happens at high level:

For PHP. You request "script.php" your webserver notices its configured
to do "something" with files with the ".php" extension, there's a
"handler" built into the web server that gets handed your request, which
has a buncha text, that's it. The handler opens script.php on the local
filesystem, parses and executes the code based on the request and gives
the web server back an html document, which the web server than gives to
you. This means, NONE of your php code is ever transmitted to the
client. Its interpretted on the server somewhere in the webserver's
request handling timeline.

For Perl CGI, its a little different. The webserver gets a request for
/cgi-bin/perl.cgi and goes "hrm, this is a script directory, meaning
requests have to be for executable files!". The web server check for
the execute bit on the script, and then executes that script redirecting
the entire request header to the STDIN of the script. You know why you
put this line:

#!/usr/bin/perl

on all your scripts? Because that's how the OS figures out which
interpretter to use to execute the following code. apache actually
doesn't even know its executing perl. You can put binary files in the
cgi-bin that don't use interpretters. You can compile some c program,
put it in th cgi-bin and have it execute, granted unless you know what
you're doing, that's not a good idea at all, but, you get the idea.

So in closing.

you're original request makes no sense whatsoever.

If you want Perl to generate a PHP source file and then execute that,
YOU can do that..

Its a little tricky and slow as you'll have to run it through the CGI
model using the old school UNIX technique of piping by using a wrapper
script.

#!/bin/sh

/usr/bin/perl /web/root/cgi-bin/thing.pl |/path/to/php

>
> Thanks to all for replies!
>
> --
>
> ...m8s, cu l8r, Brano.
>
> ["Bother!" said Pooh, as Piglet sacrificed him to the dark gods.]
>
>
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


--
Brad Lhotsky <brad@divisionbyzero.net>
Thomas Bätzler

2005-02-04, 3:55 pm

Ing. Branislav Gerzo <konfera@2ge.us> asked:
> user come to website, write in textbox some IPs, I want send
> this input to my perl script (parse that text, takes IPs, do
> operation with them - insert them to database, check
> them...), and send results via _PHP_ to user.


I have a really nasty idea how to do this ;-)

In your Perl script, open a pipe to a php interpreter
binary (php4-cgi on Debian) and feed your PHP code to that.
The interpreter's output will then be sent to the end user.

e.g.

open( PHP, "|/usr/bin/php4" ) or die "Can't start PHP interpreter: $!";

select( PHP );

print '<? echo phpinfo(); ?>';


HTH,
Thomas

"everything looks like a nail if a hammer is all you have"
Nestor Florez

2005-02-04, 3:55 pm

How about this:

1) first page is php with action to a perl page

2) page is a perl page that process the info and redirects to a the first page

3) back to first page but here you check the referrer and if it is a perl page then
display your data other wise is just the first time the php page gets called.

Nestor :-)

-----Original Message-----
From: "Ing. Branislav Gerzo" <konfera@2ge.us>
Sent: Feb 4, 2005 6:23 AM
To: beginners-cgi@perl.org
Subject: Re: Perl out to PHP

Paul Archer [PA], on Friday, February 4, 2005 at 08:14 (-0600 (CST))
thinks about :
[color=darkred]

PA> Understood. My point was more along the lines of: "What do you really want
PA> to do, and why don't you state that clearly, instead of making us
PA> mind-read?"

ok, sorry then. We have website done with PHP, it did my brother. But
I'm more into perl, so I did some scripts. Website is about checking
IPs (if it is up, and so on), so I wrote script for that. Ok, now my
problem:

user come to website, write in textbox some IPs, I want send this
input to my perl script (parse that text, takes IPs, do operation with them -
insert them to database, check them...), and send results via _PHP_ to
user.

Thanks to all for replies!

--

...m8s, cu l8r, Brano.

["Bother!" said Pooh, as Piglet sacrificed him to the dark gods.]



--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>





Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com