Solved

CGI variables to PHP

Posted on 2004-08-02
4
333 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

758 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

17 Experts available now in Live!

Get 1:1 Help Now