1

I have multiple php scripts to ping each of our locations, and I'm trying to list all results on one page.

Here's the ping script:

<?php
  $host  = "10.10.10.10"; //IP adress to ping
  $loc = ("HQ"); //Name of location
  $output = array();
  echo("<b>$loc</b> <i>(IP: $host)</i> is ");
        exec("ping -n 1 $host 2>&1", $output);
     //print_r($output);
      //you can use  print_r($output)  to view the output result
      if (count($output) > 7) {
        $output = null;
        die ("<font color='green'><b>up</b></font>");
        }
        else {
        $output = null;
        die ("<font color='red'><b>down</b></font>");
        }       
?>

So, I have many php files with this script, where the only difference is host and loc. I've tried to include each file in a new php file using include like this:

<?php
include "file1.php";
include "file2.php";
include "file3.php";
...and so on...
?>

But this only outputs the result of the first file.

How can I do this in any other way?

Thanks!

1
  • 2
    using die means you are exiting your code. you should use echo instead of die Commented Apr 22, 2015 at 10:43

1 Answer 1

4

die(), or its equivalent exit() ends the script. Simply change die() to echo as in:

if (count($output) > 7) {
    $output = null;
    echo "<font color='green'><b>up</b></font>";
} else {    
    $output = null;
    echo "<font color='red'><b>down</b></font>";
}    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.