Ok, i honestly have no idea where to begin with this but I am trying to make a script that will go through a certain amount of URL's and look for one of them that is valid. Basicly I am trying to make a script that will look at the following URL. mywebsite.com/atn/1b7da100.htm see if it is a valid page, if it returns a 404 it will move to page mywebsite.com/atn/1b7da101.html So it will check through all pages 100-999 until it finds the right url then it will stop. mywebsite.com/atn/1b7da(changethisnumber).html Any suggestions on how i could accomplish this?
<?php for($i=100; $i<=999; $i++) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'mywebsite.com/atn/1b7da' . $i . '.html'); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http_code != "404") { echo $response; break; } } PHP: Untested but should work. If a 404 isn't returned it'll output the contents of the page.