6

If i want to do multiple things (that require cookies) with curl, for example:

  1. login to (my own) blog
  2. then automatically submit a blog post

do I do this in one curl instance before curl close or do i close first session and then start second one for second task? (Sorry if it's dumb question but i can't quite get it. Generally all examples on the net i find about curl are doing only one thing... this doesn't help me with understanding it.)

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
Phil
  • 3,628
  • 8
  • 34
  • 36

2 Answers2

9

Generally speaking:

  1. Initialize curl. (curl_init, or curl_multi_init)
  2. Do thing(s). (in multiple curl_exec calls if needed, or curl_multi_exec)
  3. Close curl. (curl_close or curl_multi_close)

So yes, all in one session.

karim79
  • 339,989
  • 67
  • 413
  • 406
  • Ok... so let's say i'm using code from this question http://stackoverflow.com/questions/728274/php-curl-post-to-login-to-wordpress to login into my blog... how do i add post submitting? Should I add my code after curl exec but before curl close? Can I just add different curl_setopt parameters (url, referrer, etc) and exec it again with these parameters? Or what i'm talking is total nonsense? ;) – Phil Aug 14 '09 at 01:20
  • 3
    @Phil - yep, add different parameters, set different operations, call curl_exec, and do the same again, and call curl_close when you're *done* done. – karim79 Aug 14 '09 at 01:23
0

Yes open and close each curl object before moving to the next.

RiddlerDev
  • 7,370
  • 5
  • 46
  • 62