Functie Ping IP in PHP

Acum ceva vreme aveam nevoie sa dau ping unui ip din PHP fara a avea un VPS sau Dedicat, asa ca am cautat un serviciu care ofera aceasta optiune si am codat o functie in acest sens. Aceasta verifica daca un ip este sau nu online. Sper sa va fie de folos! 🙂

<?php
function verifica($ip)
{
$da=file_get_contents("http://www.ajaxutils.com/ping/ajax.php?query=$ip");

$findme   = ', 0 received';
$pos = strpos($da, $findme);
if ($pos !== false) {
     return 'Offline';
} else {
     return 'Online';
}
}
echo verifica('127.0.0.1');
?>

Silviu Stroe
I'm Silviu and I run Brainic, a mobile-focused software agency. I'm also a member of Nokia and Yahoo wall of fame. My interests are in low-code/no-code development and bleeding-edge technologies.

Leave a Reply

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