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
Solved

CGI variables to PHP

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 179
importing users to Security group 2 55
Access Control Entries lost in Windows folders 3 57
Sums of coloumns in html/java 15 80
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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