Solved

CGI variables to PHP

Posted on 2004-08-02
4
339 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 63 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 62 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

Technology Partners: 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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

734 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