Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
12-02-2008, 07:52 AM #1
- Join Date
- Mar 2008
- 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
(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.
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
12-02-2008, 01:58 PM #2
- Join Date
- Jun 2003
- Cottage Grove, Minnesota
- Thanked 1,072 Times in 1,063 Posts
I don't understand what the "cookies" part is all about.
12-02-2008, 02:05 PM #3
I am going to assume that you are going to use the same cookie information on each posted.
$posturl = YOUR URL HERE; //exp: http://example.com/post.php
$filename = PATH AND FILENAME //exp: ./filename.txt
$cookie = PATH AND FILENAME //exp: ./cookies.txt
$file = fopen($filename, "r");
$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);
$result = curl_exec($ch);
echo "<p>Posted ".$userid."</p>";
Last edited by kokjj87; 12-02-2008 at 06:08 PM.