Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exec() not working

Status
Not open for further replies.

cesarcesar

Programmer
Mar 5, 2003
30
Hello all,

How to get the $response var to return with a value in it.
____________________________________

www.site1.com/test1.php
Code:
$post_array = array(
	 "test1"	=> "a"
	,"test2"	=> "b"
	,"test3"	=> "c"
);

// Convert Array to POST string (key_1=val_1&key_2=val_2...)
reset($post_array);
while (list ($key, $val) = each($post_array)) {
	$data .= $key . "=" . urlencode($val) . "&";
}

exec("/usr/bin/curl -m 120 -d \"$data\" [URL unfurl="true"]http://www.site2.com/test2.php[/URL] -L", $response);

// $response returns empty. i need this to have the new $_POST vars in it
print_r($response);
____________________________________

www.site2.com/test2.php -
Code:
// my own function. working fine.
custom_insert('test_db');

// set new $_POST vars.
$_POST['x'] = "x";
$_POST['y'] = "y";
$_POST['z'] = "z"; 

// this is not returning properly.
Return $_POST;
 
hi,

I have had the same experiance. I my case I wrote a case to the support at the web hotel and they told me that this was turned off for security reason.
 
OK i got schooled by some 15 year old kid named "Sliver". man i hope i have a job in a few years!!! This is what he had to say about exec() vs. CURL.
I think you are misinterpreting what CURL is used for. It should be used when you need to execute a form on another site and possibly capture the output which would be HTML, like a normal page. Since you have control of both pages that you are using CURL for, there is no real point.

If you have to use CURL, keep in mind that the CURL response is generally the output of a normal page, not a variable. Therefore, capturing a variable through CURL output would not too easy.

I have listed my working code below for any one interested. It basically takes an array (form elements) and passes them to another file on another machine, then passes vars back to the main server. Check this out..

1. Site 1 on Server A sends $_POST vars from to Site 2 on Server A.
2. Site 2 on Server A then sends the same $_POST vars to Site 3 on Server B.
3. Site 3 on Server B processes the $_POST vars.
4. Site 3 on Server B then sends back $responce vars to Site 2 on Server A.
5. Site 2 on Server A then sends $responce vars to Site 1 on Server A.

Put that in your pipe and smoke it. think i will. enjoy, thanks for all the help.

-
Code:
<?php 
$post_array = array(
	 "test1"	=> "x"
	,"test2"	=> "y"
	,"test3"	=> "z"
);

// Convert Array to POST string (key_1=val_1&key_2=val_2...)
reset($post_array);
while (list ($key, $val) = each($post_array)) {
	$data .= $key . "=" . urlencode($val) . "&";
}

exec("/usr/bin/curl -m 120 -d \"$data\" [URL unfurl="true"]http://www.siteA.com/curl2.php[/URL] -L", $response);
$response_unserialized = unserialize($response[0]);
print_r(response_unserialized);
?>

-
Code:
<?php 
$response = serialize($_POST);
echo $response;
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top