Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for an internet connection

Status
Not open for further replies.

MrBelfry

IS-IT--Management
May 21, 2003
289
Hey

I'm developing a couple of scripts to serve as an intranet. Some of the scripts allow the user to update a db on a remote server BUT as we're on dialup I wanted to check to see if there is an internet connection available before I give them the option. My feeble newby mind has come up with this:
Code:
if(@fsockopen('[URL unfurl="true"]www.google.co.uk',[/URL] 80, $errno, $errstr, 10)) echo 'connection available'; else echo 'connection not available';
But I'm wondering if there is a better way?

MrBelfry
 
Are you running php on a local web server or is the php a command line program?
 
MrBelfry:
fsockopen() is probably a good way to check.

Just keep in mind, however, that using a URL rather than a quad-dotted IP address as the target of your fsockopen() invocation not only checks for the existence of a connection to the internet, but also requires that your DNS system be working correctly.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top