Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Multiple posts in cURL / handle text files

    Okay. let me give you an example of what I am doing.

    I have a text file full of values. Lets just say that text file contains
    1
    2
    3
    4
    5
    (hince the line break (aka \n))

    I also have a txt file that contains the cookies needed to pass those.

    What I want curl to do is go down the line of that php file and post the values as the userid , using the cookies in the cookie txt file.


    So here is a more detailed example of what i need it to post.
    userid=1
    userid=2
    and so on (based on the stuff in the TXT file)

    and after each one gets posted. It will echo "posted 1" "posted 2" , etc


    If you feel like I didn't explain this well enough, please let me know.

    Help is greatly appreciated

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I don't understand what the "cookies" part is all about.

  • #3
    Regular Coder kokjj87's Avatar
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    279
    Thanks
    1
    Thanked 55 Times in 54 Posts
    I am going to assume that you are going to use the same cookie information on each posted.

    PHP Code:
    <?php
        $posturl 
    YOUR URL HERE;     //exp: http://example.com/post.php
        
    $filename PATH AND FILENAME //exp:   ./filename.txt
        
    $cookie PATH AND FILENAME   //exp:   ./cookies.txt

        
    echo "<p>Start</p>";

        
    set_time_limit(0);
        
    $file fopen($filename"r");
        while(!
    feof($file))
        {
            
    $str fgets($file);
            
    $break   = array("\r\n""\n""\r");
            
    $replace '';
            
    $userid str_replace($break$replace$str);
            
            
    $ch curl_init();
            
    curl_setopt($chCURLOPT_URL$posturl);
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($chCURLOPT_COOKIEFILE$cookie);
            
    curl_setopt($chCURLOPT_COOKIEJAR$cookie); 
            
    curl_setopt($chCURLOPT_POST1);
            
    curl_setopt($chCURLOPT_POSTFIELDS,"userid=".$userid);
            
    $result curl_exec($ch);
            
    curl_close($ch);
            echo 
    "<p>Posted ".$userid."</p>";
        }
        
    fclose($file);
        
        echo 
    "<p>Finish</p>";
    ?>
    Last edited by kokjj87; 12-02-2008 at 06:08 PM.


  •  

    Posting Permissions

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