Who can tell how in JavaScript or PHP to check the correctness of the page load when executed, let's say the script generates the address http://cs10374.vkontakte.ru/u69126676/a_eab3c25c.jpg , and if the page does not load or error 404, then the script does not accept this the address, and if http://cs10374.vkontakte.ru/u69126676/a_eab3c24c.jpg , the page is loaded, the script saves the address. Some such work, I will be very grateful.

    1 answer 1

    It is possible so:

     $urls = array( "http://cs10374.vkontakte.ru/u69126676/a_eab3c25c.jpg", "http://cs10374.vkontakte.ru/u69126676/a_eab3c24c.jpg", ); stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); foreach ($urls as $url) { $status = get_headers($url); if ($status !== FALSE) { if (strpos($status[0], "200 OK") !== FALSE) { echo $url, " - EXISTS\n"; } else { echo $url, " - not exists\n"; } } else { echo "Error request for ", $url, "\n"; } } 

    Here a HEAD request is used, if via GET then stream_context_set_default removed

    • and if the script has to cycle through the necessary numbers (from 20 to 30 where it changed), then how - Semyon
    • one
      And where did you change? In the URL? If you select a URL, then it is easier to generate it: for ($ i = 20; $ i <= 30; $ i ++) {$ url = sprintf (" cs10374.vkontakte.ru/u69126676/a_eab3c%02dc.jpg ", $ i) ; ...} - chernomyrdin
    • one
      I don’t know that, I don’t have it with Windows. With regards to ... there should be $status = and all that is in response - chernomyrdin
    • one
      And what to write here: for ($ avatar = 1; $ avatar <= last_number_avatar; $ avatar ++) {for ($ id = 1000000; $ id <= last_number_id ; $ id ++) {$ url = sprintf (" i01.fsimg.ru /%d/user_big/%s/%s/%d.jpg ", $ avatar, substr (strval ($ id), 0,3), # the first 3 digits of the number substr (strval ($ id), 0.5 ), # the first 5 digits of the number $ id # number in full); }} - chernomyrdin
    • one
      @Semen, you were told a lot more than was in your question. If you don’t understand php at all (what the code you copied says) to you on free-lance.ru . The price of such a script is $ 10. - Sh4dow