1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with a site-scanning script

Discussion in 'Programming' started by zer0k1, Sep 12, 2016.

  1. #1
    I have a specific URL that I would like a scaript to change 1 digit of the URL by counting up and every time the link is valid I want it to save that link and continute on. If the link is invalid it will just say page no availible, if it is valid then it will redirect to a new URL. Because of this I can't seem to get a viable PHP script. But maybe there is an easier way to do this...

    Here is what I tried so far as was unsucessful with:

    
    <?php
    
    $context = stream_context_create(
    array(
    'http' => array(
    'follow_location' => true
    )
    )
    );
    
    $start = $_GET['start'];
    $end = $_GET['end'];
    
    echo 'Testing urls starting with: ' . 'https://www.******.***/***/1234567/***' . $start . '<br/>';
    
    for ($i = $start; $i <= $end; $i++) {
    
    $url = 'https://www.*******.***/***/G964999422' . $i . '/***';
    
    
    
    $html = file_get_contents($url, false, $context);
    
    if ($i == $start)
    echo $html;
    
    
    PHP:
    Please help!
     
    zer0k1, Sep 12, 2016 IP
  2. NaughtySpider

    NaughtySpider Peon

    Messages:
    10
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #2
    <?php
    
    // setup curl
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_HEADER, true);
    
    // where to start and when to stop
    $start = 1;
    $end = 100;
    
    foreach (range($start, $end) as $current) {
      // current url
      $url = "http://example.com/{$current}";
    
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_exec($curl);
    
      // get http code from header
      $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    
      // check if http code is not successfull (read more here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
      if ($httpCode != 200) {
        echo "Something is wrong with {$url}\n";
      }
    }
    
    curl_close($curl);
    PHP:
    Also I noticed what you get $start and $end from $_GET array. Run this kind of scripts from terminal. This way you will see results instantly, without browser loading screen.
     
    NaughtySpider, Sep 15, 2016 IP