Hi all,
I m doing on passing variables from php to cgi
I've tried some methods already but it didnt work.
- Header function:-
header("Location:http://myserver/myfile.php?a=$a&b=$b");
Then in my cgi script:-
if ( $ENV{QUERY_STRING} )
{
my $buffer = $ENV{QUERY_STRING};
my %QUERY_STRING;
if ( length($buffer ) > 0 )
{
my @pairs = split(/&/, $buffer);
foreach my $pair (@pairs)
{
my ($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$QUERY_STRING{$name} = $value;
}
}
$a= $QUERY_STRING{a};
$b_id = $QUERY_STRING{b};
}
I used query string to receive the values but nothing.
- Then second i used curl to pass values:-
$ch = curl_init("http://myserver/myfile.cgi"); // initialize curl handle
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_POSTFIELDS, "a=$a&b=$b"); // add POST fields
$Response = curl_exec($ch);
curl_close($ch);
echo $Response;
Both i used query string but received nothing.
One thing which funny is that:
in curl, if i change url to www.google.com and else which got 'www' at front, i can read the response.
I m doing on the test server, without www at front of my url, but would that be the problem for me couldnt use CURL?
please help and welcome every suggestions!