slpctrl Posted June 16, 2008 Share Posted June 16, 2008 Okay, here's what I'm trying to do: there's a site I know, and there are contents on each numerical page like so: www.site.com/1.htm www.site.com/2.htm etc etc. Now, I'm trying to brute force to find a certain page. Here is my code I've got thus far: <?php $i = 1; if($i < 135) { $newfile = file_get_contents("http://site.com/$i.htm"); echo $newfile; sleep(3); $i++; } ?> But it doesn't work. I can't really understand why. Any help?? ??? Quote Link to comment https://forums.phpfreaks.com/topic/110358-url-reading/ Share on other sites More sharing options...
Stephen Posted June 16, 2008 Share Posted June 16, 2008 Well if you want it to keep looping you can't just use if. Maybe try using this? D: <?php $i = 1; do { $newfile = file_get_contents("http://site.com/$i.htm"); echo $newfile; sleep(3); $i++; } while ($i<135); ?> Otherwise I think it should work? D: Unless your site doesn't allow file_get_contents. Quote Link to comment https://forums.phpfreaks.com/topic/110358-url-reading/#findComment-566237 Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 minor bitch, but do..while loops are meant for conditions that don't have a set amount of iterations to them, or for when you don't know how many iterations there will be. If you know how many iterations there will be, use a for loop instead. It's a minor detail and having an outside $i var increment like that works too, but I mean, that's the point of a for loop for ($i = 1; $i < 135; $i++) { // code here } Just FYI, regardless of how you loop it, understand that php is a server side language. It will completely run its course before spitting things out to your browser. Depending on how much content is on those target pages, it may take a while to see some results, and your script may even time out. In a case like this, I would probably suggest using javascript to make a loop and send requests individually, instead. Quote Link to comment https://forums.phpfreaks.com/topic/110358-url-reading/#findComment-566240 Share on other sites More sharing options...
Stephen Posted June 16, 2008 Share Posted June 16, 2008 Yeah, so many different kinds of loops, that's why I hate 'em! Quote Link to comment https://forums.phpfreaks.com/topic/110358-url-reading/#findComment-566271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.