Jump to content

URL reading..


slpctrl

Recommended Posts

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??  ???

Link to comment
https://forums.phpfreaks.com/topic/110358-url-reading/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/110358-url-reading/#findComment-566237
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/110358-url-reading/#findComment-566240
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.