Opa Thanks for the guide. I ended up finding a solution in jQuery, basically it is an external service where it requests the site I want to consult and returns an object json with the site information (variavel.status) or the whole Html of the site.
I found a solution also in PHP who does something similar, but who gathers more information and does not need an external service. I’ll leave the code here for those who have to build a similar solution.
Javascript:
$.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://www.facebook.com') + '&callback=?', function(data){
if(data){
console.log(data.status);
}else{
return("servidor offline");
}
});
<!DOCTYPE html>
<html>
<head>
<title>Angular Curl</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
</head>
<body>
<h3 style="text-align: center">Mostre o Console para ver o Retorno do Objeto</h3>
</body>
</html>
And below in PHP:
<!DOCTYPE html>
<html>
<head>
<title>Ping Site</title>
</head>
<body>
<?php
function curl_info($url){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
// curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
$content = curl_exec( $ch );
$info = curl_getinfo( $ch );
return $info;
}
$site = 'http://www.honda.com/';
$info = curl_info( $site );
if( $info['http_code']==200 || $info['http_code']==302 || $info['http_code']==301) {
echo '<u>'.$site . "</u> - <b style='color:lightgreen; font-size: 18px; text-transform: uppercase'>está no ar!!</b><br />";
var_dump($info);
} else {
echo '<u>'.$site . "</u> - <b style='color:red; font-size: 18px; text-transform: uppercase'>está fora do ar!!</b><br />";
var_dump($info);
}
?>
</body>
</html>
See if the example below helps you. http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript
– Ismael
Okay Ismael, or take a look there now... Thank you!
– Matheus Alves
Hello Ismael, unfortunately it didn’t work...
– Matheus Alves
There is an alternative to knowing if it is 200 or if it is different from 200, without getting the exact code, that is it can be 400, 500... I don’t know if that would be enough for your case.
– Inkeliz
Hello Inkeliz, it would be interesting too.
– Matheus Alves