1

Some links fail even though they are accessible

<!DOCTYPE html>
    <html lang="en">

    <?php
            require('simple_html_dom.php');
            include('connect.php');
            ini_set('error_reporting', E_ALL);
            ini_set('display_errors', 1);
            $query = mysqli_query($con,"SELECT * FROM link2");



    ?>


     <table id="keywords" cellspacing="0" cellpadding="0">
     <thead>
          <tr>
                    <th class="text-left">NAME</th>
                    <th class="text-left">NAS IP</th>
                    <th class="text-left">MAX IN</th>
                    <th class="text-left">MAX OUT</th>
                    <th class="text-left">STATUS</th>
                    <th id="nm">BEEP</th>
          </tr>
         </thead>
        <tbody  class="table-hover">


    <?php   

Here I am looping through the urls from the db and checking for connection. Settings of my php.ini file seem to be working correctly

while($row = mysqli_fetch_array($query))
{
    $name = $row['name'];
    $url = $row['links'];
    $html = @file_get_contents($url);
if ($html)
{
    $state = "ACCESS";
    $html = file_get_html($row['links']);                           
    $in = $html->find('p', 0)->children(0);
    $trial = explode(";",$in);
    $in = (strip_tags($trial[0]));
    $out = $html->find('p', 0)->children(2);
    $trial2 = explode(";",$out);
    $out = (strip_tags($trial2[0]));
    $str = $in;
    preg_match_all('!\d+(?:\.\d+)?!', $str, $matches);
    $floats = array_map('floatval', $matches);
    $int = (float)$matches[0][0];
    $str2 = $out;
    preg_match_all('!\d+(?:\.\d+)?!', $str2, $matches);
    $floats = array_map('floatval', $matches);
    $int2 = (float)$matches[0][0];

    if($int < $row['min'] || $int2 < $row['max'])
    {
        $display = "BEEP";

    }   
else{
        $display = " ";

    }   

Displaying the table

echo "".$row['name']."".$row['nas_ip']."".$in."".$out."".$state."".$display.""; } else { $state = "NO ACCESS"; $display = "BEEP";

        echo "<tr><td>".$row['name']."</td><td>".$row['nas_ip']."</td><td></td><td></td><td>".$state."</td><td>".$display."</td></tr>";
    }   




    unset($html);

}   
?>

</tbody>
</table>


</body>
</html>

enter code here
mymiracl
  • 583
  • 1
  • 16
  • 24
Nikhil Prasad
  • 65
  • 1
  • 10
  • You can reduce your question to this line: I can not load content via `file_get_contents($url);`, but the url is accessible. Maybe explain what `accessible` means here? Via Browser, curl, wget, .... – JustOnUnderMillions Jan 23 '17 at 14:30
  • i mean when i access them from the browser i can connect with them instantly but when through the array some fail to connect and get the contents..sorry about the way the question was framed.new here :) – Nikhil Prasad Jan 23 '17 at 14:32
  • `access them from the browser` that is maybe the problem, did you know that an browser send an full HTML HEADER but `file_get_contents` does not. It seems that you are blocked when calling a given URL from php via `file_get_contents`. If the server behind the url not get the HEADER he needs he may block you ( for the server you are looking like an web-bot). Read more here: http://stackoverflow.com/questions/2107759/php-file-get-contents-and-headers – JustOnUnderMillions Jan 23 '17 at 14:55
  • And read here about the use of `cUrl` instead of `file_get_contents` http://stackoverflow.com/questions/6649189/downloading-and-saving-file-by-using-wget-in-shell-exec – JustOnUnderMillions Jan 23 '17 at 14:58

0 Answers0