Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CGI variables to PHP

Posted on 2004-08-02
4
Medium Priority
?
341 Views
Last Modified: 2013-12-25
I have an HTML form that sends data  (through POST form)  to a cgi script that connects to a third party service and returns values from the third party service.The problem is that the CGI script prints out returned data.This is completely wrong.I need to be able to work with the returned values..
I would like to have those CGI variables forwarded to my PHP script, where I could work with them.
My question is :
How can I forward those CGI variables to a php script ?

I do not know CGi programming at all, but I know PHP very well.
I guessed it might be doable to send the CGI variables through HTTP header (to put them as POST variables into th eheader) and then to forward or redirect (Location:http://www.somewhere.com/somescript.php)
the whole output to the PHP script.

Is that possible ?
Thanks a lot
Martin
0
Comment
Question by:thegoodbyte
[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
4 Comments
 
LVL 9

Accepted Solution

by:
dutchfoxer earned 252 total points
ID: 11711330
Hmmm not easy. It is adviced to use like an XML file for sharing variables / values, or a text file.

Would be nice if you could call a PHP script from perl like this: somescript.php?var1=210

Look at this link:
http://search.cpan.org/~esummers/PHP-Include-0.05/

You could also have a PhP-script calling the Perl-script which returns values, right?

Found the following code, might be usefull I hope:


<?
$CGISCRIPT="./cgi-bin/cgiscript.cgi";
// preparing the arguments passed to this PHP page
$QSTRING = $QUERY_STRING;
foreach ($HTTP_POST_VARS as $header=> $value ){
if($QSTRING==""){
$QSTRING = $header.'='.urlencode($value);
}else{
$QSTRING = $QSTRING.'&'.$header.'='.urlencode($value);
}
}
putenv('REQUEST_METHOD=POST');
putenv('CONTENT_TYPE=application/x-www-form-urlencoded');
putenv('CONTENT_LENGTH='.strlen($QSTRING));
putenv('QUERY_STRING='.$QSTRING);
unset($return_array);
exec('echo "'.$QSTRING.'"| '.$CGISCRIPT, $return_array, $return_val);
$firstline=array_shift($return_array);
//evaluate the code
eval('?>'.implode($return_array,''));
?>
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 248 total points
ID: 11729945
> I need to be able to work with the returned values..
hmm, simply change your CGI to do what you want ;-)

> How can I forward those CGI variables to a php script ?
if it is apache2 then see configuration of OUTPUT_FILTERS (sorry have never done it this way)
otherwise you need to call your php script and pass the values as arguments from within your CGI (ho to do this in PHP, see above comment)
or you can do it a bit more cumbersome and form a POST request tou your own server's PHP script, parse the return and send it back to the browser

>Is that possible ?
i.g. yes, more or less cumbersome
The way to go is either do it all in your CGI, or do it all in PHP, but not both
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 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