Check internet connection with php

determine in php script is connected to internet

×

Hi, we do internet connection control with this article in PHP example.

How do i know if connect to the internet?

if 80th port returns true, know internet connection is successfully.

look at the example;

function is_connected()
{
    $connected = @fsockopen("www.some_domain.com", 80); 
                                        //website, port  (try 80 or 443)
    if ($connected){
        $is_conn = true; //action when connected
        fclose($connected);
    }else{
        $is_conn = false; //action in connection failure
    }
    return $is_conn;

}

What does it do?

💬 Yorumlar
Henüz yorum yapılmamış. İlk yorumu sen yap! 👆