Multiple cURL requests
I've never touched cURL but I think I am going to get my feet wet! :)
How do I submit multiple requests to post.php?
Post: id = 4
Post: id = 5
Post: id = 1
If it makes any difference, I do not want to need to get a response from the server...
this is probably not the answer you want but curl gets deep quick
this shows you how to log in or just post to a field, remember loggin in is just the same as posting a form
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://www.'.$myuserver.'/login.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
echo "we log into wd at $myuserver with user name $myuname and pass $myupass";
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username='.$myuname.'&password='.$myupass);
//curl_setopt ($ch, CURLOPT_POSTFIELDS, 'form_request=login&origin=admin&auth_source=my formfiel1&username='.$myuname.'&password='.$myupass);
// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false so we can echo out the page view.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
Originally Posted by lorenw
If I want to submit it twice, do I actually have to basically copy that, or is there a way to send subsequent requests (to the same page)
To make repeat request:
1. Don't close the curl session with curl_close() after executing the curl_exec() for the first time.
2. Alter the options that you want to change in the next request e.g. you wouldn't want to change the option CURLOPT_URL (because you want to submit to the same page) but you would want to change the option CURLOPT_POSTFIELDS (because you want to submit different set of values) .
3. execute the curl session again with curl_exec() . All Unaltered options will retain the original values (ones that were set in the beginning).
4. Hope this makes sense!
for CURLOPT_URL, can I do soemthing like remote.php?getvar=getvalue ???
The remote.php page will modify $_SESSION but it seems it doesn't quite work... how do I make it pass the current session?