Code to check for internet connection not working

I am trying to find some code that will let me check for an internet connection or no connection.

I found the code below from this post: Link

Here is my small test.php script. It shows a connection when I run it but when I turn off my wifi connection it doesn’t tell me there is no connection.

test3.php (1.7 KB)

Your code checks if you’re online by checking a page on the same server as test3.php. So you’re testing if someone was online, went to your page, and then suddenly their connection had a heart attack.

Not… entirely sure i see the use case, but sure…

Your invocation of isOnline inside your timer is missing the parameters. isOnline takes 2 parameters, and expects them to be functions. If you pass it nothing, your function will do nothing.

Hmmm…I see. I added the arguments:

function myTimer() {

0 is a false (no) and 1 is a yes (1).

When the timer hits, I see a msg: test3.php:31 GET net::ERR_INTERNET_DISCONNECTED

Are those arguments correct data types or should I be sending in strings data types?test3.php (1.7 KB)

So i’m gonna go ahead and guess you stole this code from somewhere, don’t know what it does, and are just hoping poking at it randomly will make it work correctly.

You have a working example of what should be passed as the parameters on lines 37-44 of your code.

Yes, I posted the link in my first post where I got this code from.

I was thrown by how the function arguments are shown. I added the call in the timer with the two functions per your last reply and help and the console is showing the correct messages now.

Using Chrome I am still seeing the “GET net::ERR_INTERNET_DISCONNECTED” message in the console when I disconnect the wifi but I’m guessing that won’t hurt anything as long as the correct messages are being caught (and it seems they are). In FF that message does not display at all, just the yes() no() messages.

Thank you very much for your help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.