...

View Full Version : Multiple posts in cURL / handle text files



WebmasterLULZ
12-02-2008, 07:52 AM
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 :)

mlseim
12-02-2008, 01:58 PM
I don't understand what the "cookies" part is all about.

kokjj87
12-02-2008, 02:05 PM
I am going to assume that you are going to use the same cookie information on each posted.



<?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($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"userid=".$userid);
$result = curl_exec($ch);
curl_close($ch);
echo "<p>Posted ".$userid."</p>";
}
fclose($file);

echo "<p>Finish</p>";
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum