iAreCow Posted October 30, 2009 Share Posted October 30, 2009 So I have a tiny problem with arrays, basically I have to store 239 values in an array, later use foreach(); to process them all. I have the last part working but there are complications with the first one. 1. I submit values using textarea, putting each value on each row, then later I explode(); to get the values into an array. If I print_r();, everything looks fine, arrays from 0-239 show up. <form method="POST"> UserIDs: <textarea name="userids" cols="75" rows"100"></textarea> <input name="submit" type="submit" /> </form> <?php set_time_limit(0); ignore_user_abort(true); $ids = $_POST['userids']; $exp = explode("\n",$ids); print_r($exp); // The values show up correctly when print_r();'ing them foreach ($exp as $uinfo) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://sitetovisit.com/users.php?id={$uinfo}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec ($ch); curl_close ($ch); } ?> Yet, after processing all of them, the server replies with error 400 from 0-238, yet, 239th value is processes correctly. 2. This one works just fine (all array values get processed without 400 server errors), but Im missing a feature here - textarea submitting (yes this one has only 3 values in the array, but Im too lazy to do more.) <?php set_time_limit(0); ignore_user_abort(true); // $ids = $_POST['userids']; // $exp = explode("\n",$ids); // print_r($exp); $ids = array("1662683", "2040182", "1690671"); print_r($ids); foreach ($ids as $uinfo) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://sitetovisit.com/users.php?id={$uinfo}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec ($ch); curl_close ($ch); } ?> Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/ Share on other sites More sharing options...
jonsjava Posted October 30, 2009 Share Posted October 30, 2009 It sounds like you may be killing the remote server with the mass requests, but you're only hitting it 239 times. Either their server isn't very powerful, or they have an anti-ddos system in place that is blocking your requests. Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/#findComment-947985 Share on other sites More sharing options...
iAreCow Posted October 30, 2009 Author Share Posted October 30, 2009 Cant be true, this script does about the same work (just using range(); ) and works just fine. <form method="POST"> UserID from: <input name="from" value="2038700" size="50" /><br> UserID to: <input name="to" value="2133012" size="50" /><br> <input name="submit" type="submit" /> </form> <?php set_time_limit(0); ignore_user_abort(true); if (!isset($_POST['submit'])) die(); $from = $_POST['from']; $to = $_POST['to']; foreach (range($from, $to) as $uinfo) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://sitetovisit.com/users.php?id={$uinfo}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec ($ch); curl_close ($ch); } ?> Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/#findComment-947994 Share on other sites More sharing options...
cags Posted October 30, 2009 Share Posted October 30, 2009 My guess is the page breaks are \r\n, so when you break on \n there are still \r's on the end of the line which is breaking the request, the last line works because there are no page breaks after it. Swap your explode statement to split on \r\n. Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/#findComment-947997 Share on other sites More sharing options...
iAreCow Posted October 30, 2009 Author Share Posted October 30, 2009 And the problem is fixed! Thanks everybody! Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/#findComment-947998 Share on other sites More sharing options...
cags Posted October 30, 2009 Share Posted October 30, 2009 No problem. Don't forget to marked it solved, button in bottom left of screen Link to comment https://forums.phpfreaks.com/topic/179667-solved-problem-with-arrays/#findComment-948000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.