1

I just want to write a php code to check if password protected website is online or offline. I know the code to check whether if website is online or offline but it is not working if the website is password protected through .htaccess. llike if you open then website then an alert box comes and ask about the user name and password. If i use this code then it is just saying that the website is offline because it cannot by pass the user name and password.

$host = 'http://gforms.orbnexus.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}

Can any one please help me? Is there any way to by-pass user name and password?

orbnexus
  • 737
  • 1
  • 9
  • 38
  • 1
    Use cURL instead, here's a good function for you http://stackoverflow.com/a/1239090/1765851 – Sven Feb 27 '14 at 17:42
  • Hi, I used this function but it is still saying fail. Please check if i am doing anything wrong here. – orbnexus Feb 27 '14 at 18:06
  • if(urlExists("http://gforms.orbnexus.com") == true){echo success';}else {echo 'fail';} function urlExists($url) { if($url == NULL) return false; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300){ return true; } else { return false; } } – orbnexus Feb 27 '14 at 18:08
  • What about logging in with your script? – oshell Feb 27 '14 at 18:09
  • How would I do it? this alert login box is coming from htaccess. How can i pass the user name and password? – orbnexus Feb 27 '14 at 18:16
  • actually I never used a htaccess login. But probably this could help you. http://www.php.net/manual/en/features.http-auth.php – oshell Feb 27 '14 at 18:36

2 Answers2

0

the fact that it asks for a username and password means its online. I'm also sure you can make sure when you send your request that you get back a header, if nothing comes back the website is down.

James Little
  • 601
  • 7
  • 24
0

Reference page

Use cURL to get your target, then check the http status code. If you get a 401 then it there's an authentication issue

Justin Kiang
  • 1,270
  • 6
  • 13