Posted By

phpdev on 01/24/13


Tagged

php web connection internet snippet


Versions (?)

Check your Internet connection with PHP


 / Published in: PHP
 

Example of use:

$bIsConnected = check_internet_connection();
$sText = ($bIsConnected) ? 'You are connected to the Internet.' : 'You are not connected to the Internet.';
echo $sText;
  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  

You need to login to post a comment.