Khalsa Labs

Ping tool in PHP

Here a small piece of code for Ping tool in PHP that pings to hosts via o.s . Only trick abot this script is that it calls the system routines for perfom function,nice feature of server side scripting.The script can be run on Linux as well as Windows by detect the server o.s itself.

The Power of PHP could be integrated with with os to perform basic operations, like this.


Enjoy the Ping tool in PHP:


<h1> Ping tool </h1>

<form action=”” method=”post”>
enter host name or ip address: <input type=”text” name=”t1″ />
<input type=”submit” value = “ping it”/>
//ping tool in php
$host = “”;
if(isset($_POST[‘t1’]) && $_POST[‘t1’]!= “”)
$host = $_POST[‘t1’];
die(“please select a host to ping”);
echo “ping results for $host <br><br>”;
$p1 = “ping -l 2 $host”;
$p2 = “ping -n 2 $host”;
echo “<br>”;
echo “<br>”;

The following two tabs change content below.
Python Developer and DIY lover.

want to comment ??

Your email address will not be published. Required fields are marked *

  • php deve. says:

    it does not display the result

  • meir says:

    how can i ping list of domains in text file?

    • Harman says:

      Hi meir, you can ping domains from text file by adding a few more lines of code for reading an uploaded text file. You have to combine the file reading code with above ping code to make it possible. All the best 🙂