Check your Internet connection with PHP


/ Published in: PHP
Save to your folder(s)

**Example of use:**

$bIsConnected = check_internet_connection();
$sText = ($bIsConnected) ? 'You are connected to the Internet.' : 'You are not connected to the Internet.';
echo $sText;


Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3.  * Check Internet Connection.
  4.  *
  5.  * @author Pierre-Henry Soria <[email protected]>
  6.  * @copyright (c) 2012-2013, Pierre-Henry Soria. All Rights Reserved.
  7.  * @param string $sCheckHost Default: www.google.com
  8.  * @return boolean
  9.  */
  10. function check_internet_connection($sCheckHost = 'www.google.com')
  11. {
  12. return (bool) @fsockopen($sCheckHost, 80, $iErrno, $sErrStr, 5);
  13. }
  14. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.