Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CGI variables to PHP

Posted on 2004-08-02
4
Medium Priority
?
343 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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…
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 …
Suggested Courses

885 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