PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$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\" http://www.site2.com/test2.php -L", $response);
// $response returns empty. i need this to have the new $_POST vars in it
print_r($response);
// 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;
You are using CURL thru the exec function, however php has the curl extension (which should be enabled almost anywhere) which will let you use curl without needing to use exec() (which is not exactly safe and secure). If you read the php page i linked to, you'll find LOTS of examples..
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok so due to some spanking by senior members in other forums i have been suggested to not use exec() function but just strait CURL. So this is what i have. the final result is a sctring when i thought i was going to get an array(). How do i get an array to show. Current out put is..
array(3) { ["test1"]=> string(1) "x" ["test2"]=> string(2) "yy" ["test3"]=> string(3) "zzz" }
Here are my files -
curl1.php -
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
nickvd wrote:You are using CURL thru the exec function, however php has the curl extension (which should be enabled almost anywhere) which will let you use curl without needing to use exec() (which is not exactly safe and secure). If you read the php page i linked to, you'll find LOTS of examples..
Can you please provide an example of how it is not safe and secure? Just to make sure Im safe and secure. Im thinking your thinking something php.ini based? Do tell.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
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.
[quote] 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.[/quote]
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.
siteA/curl2.php -
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]