SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

    For example:

    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...
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,094
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    this is probably not the answer you want but curl gets deep quick
    Code:
    $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);
    this shows you how to log in or just post to a field, remember loggin in is just the same as posting a form

  3. #3
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lorenw View Post
    this is probably not the answer you want but curl gets deep quick
    Code:
    $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);
    this shows you how to log in or just post to a field, remember loggin in is just the same as posting a form

    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)
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  5. #5
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm

    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?
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •