Answer the question
In order to leave comments, you need to log in
Javascript or PHP: check if a host is reachable?
How to use JavaScript or AJAX + PHP to check if the host exists or not? I need to check if the user has a web server running on the machine or not (localhost is available on a certain port) and if it is running, display one HTML, otherwise another.
Answer the question
In order to leave comments, you need to log in
Maybe try something like this?
var img = new Image();
$(img).load(function () {
alert('Хост доступен');
).error(function () {
alert('не загрузилась');
}).attr('src', 'ссылка на картинку на удалённом хосте');
fopen() if possible slowly, get_headers()/fsockopen() if necessary as quickly as possible
PHP:
I don't know how to determine with Javascript. Unless you send an ajax request and see if it fails or not.
$handle = fsockopen('example.com', 80);
if ($handle !== false)
{
print('работает');
fclose($handle);
} else {
print('не работает');
}
Even if it works, it will fail. In the new opera, for example, the interaction of the localhost and external sites is tightly prohibited. There is even a special error for this, I don’t remember what it’s called.
Look towards java or flash.
Damn, somehow I didn’t think myself that you could just open a socket :) But we don’t know the ip address of a person - he can sit behind a nat.
In general, what is it for? There is a client application launched by the user. And there is a website. The site must check that the application is running and the socket is available and draw a button, otherwise some kind of inscription. By clicking on the button, the site should request data from the client and receive them. How is this implemented?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question