Multiple cURL requests

Discussion in 'PHP' started by Triexa, Jul 5, 2007.

  1. #1
    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...
     
    Triexa, Jul 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The value for id would get overwritten each time. A variable cannot have multiple values unless it's an array. Or do you want to send them one by one?

    In this case do:
    
    $ids = array(1, 4, 5);
    
    $ch = curl_init('http://localhost/post.php');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    foreach ($ids AS $id)
    {
    	curl_setopt($ch, CURLOPT_POSTFIELDS, "id={$id}");
    	curl_exec($ch);
    }
    
    
    PHP:
     
    nico_swd, Jul 6, 2007 IP
  3. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    nico - yes I want to send each request... so 3 POSTs.... I've having trouble dealing with the session variables as the page POSTing to alters the session array.... how do I send/get the session variables?
     
    Triexa, Jul 7, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Try enabling cookies.
    
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    
    PHP:
     
    nico_swd, Jul 8, 2007 IP
  5. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    I believe when I did this, it worked... in the sense that when I saw output from my third request, it held data from my first request. HOWEVER, it did not translate back to my original page...
     
    Triexa, Jul 8, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Maybe this?

    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    PHP:
    If not, I don't think what you mean by "translate back to my original page".
     
    nico_swd, Jul 8, 2007 IP
  7. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    I mean, if I make my 2nd request it still has data from the first request. If I send my third request, it still has the previous 2 (as is what I want). HOWEVER, it DOES NOT have my EXISTING session data prior to my first request nor do I see how to get the session data set and apply it to current $_SESSION array... they are different session Ids I think...
     
    Triexa, Jul 8, 2007 IP
  8. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    So, anybody have any idea how to make cURL requests with the current session?
     
    Triexa, Jul 13, 2007 IP