Forum Moderators: coopster

Message Too Old, No Replies

Need Help on passing var between PHP <----> CGI

         

lovelyThumbsUp

12:11 am on Dec 6, 2008 (gmt 0)

10+ Year Member



Hey guys, I really need help on this passing value to CGI and get value back to PHP stuff work. Big Thanks

Ok Here is my current code:
------------------------------------------
<?php

ob_start();
passthru ("/usr/local/etc/httpd/htdocs/#*$!X/testing.cgi");
$results = ob_get_contents();
ob_end_clean();
echo $results;

?>

and Here is my CGI Code:
------------------------------------------
#!/usr/bin/perl -wT

sub test {

my @n;
$n[0] = 10;
$n[1] = 17;
$n[2] = 23;
return @n;
}

($first,$second,$third) = test();

print "$first-$second-$third";
----------------------------------------------

If I run the code above I got this: 10-17-23

! BIG HOWEVER !

I would like to pass a value $myNumber to $n[0];

simple say the result I hope is:

if I set $myNumber = 10000

then I got this: 10000-17-23

Big Thanks

coopster

12:16 am on Dec 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, lovelyThumbsUp.

Is this just an example? Because you certainly don't need to pass a variable to a cgi script just to get that task accomplished, you could do it right in the PHP script itself. However, if you must pass it, why not just add it to your command line execution as an argument?

lovelyThumbsUp

12:30 am on Dec 6, 2008 (gmt 0)

10+ Year Member



The reason passing and retrieving value from CGI is, I need pass a value into a CGI function (large and complex function, no time to convert to php) and get the return of that CGI function and use it in the PHP script.

And this may make it easier to under stand:
------------------------------------------
#!/usr/bin/perl -wT

sub test {

my @n;
$n[0] = $mySuperNumber(Somehow pass this value from php and use here);
$n[1] = 17;

$c = $n[0] + $n[1];

return $c;

}

($NewResult) = test();

print "$NewResult";
----------------------------------------------

Then I can use the php code above to get the value of this $NewResult

Am I make myself clear?

coopster

12:49 am on Dec 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, quite clear. As a matter of fact ...

(large and complex function, no time to convert to php)

... was all you needed to state :)

Then the second part of my response seems appropriate:

why not just add it to your command line execution as an argument

lovelyThumbsUp

3:00 am on Dec 6, 2008 (gmt 0)

10+ Year Member



well first of all, thanks for all you reply.
Secondly, I have 0 knowledage about the cgi, therefore you said:" why not just add it to your command line execution as an argument " I really have no idea how to do it? can you make a sample for me? Big Thanks!

lovelyThumbsUp

11:09 pm on Dec 7, 2008 (gmt 0)

10+ Year Member



Problem Solved!

coopster

7:55 pm on Dec 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Great! How?

lovelyThumbsUp

5:56 pm on Dec 11, 2008 (gmt 0)