PDA

View Full Version : PHP Server Online/Offline checker?



Magestickown
July 9th, 2010, 10:48
I wrote a script in PHP that I thought as much that it would not work. It didn't
(original author is whip range or some bullshit thanks to twisted for pointing this out)
1. Can you help me fix it?

or,

2. Can you link me to a tutorial/help me make one?

Thanks in advance :)

My PHP script I'm using


<?php
function GetServerStatus($site, $port) {
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
$imagepath="off.png"; //OFFLINE IMAGE LINK!
$image=imagecreatefrompng($imagepath);
header('Content-Type: image/png');
imagepng($image);
} else { //ONLINE Status
$imagepath="on.png"; //ONLINE IMAGE LINK!
$image=imagecreatefrompng($imagepath);
header('Content-Type: image/png');
imagepng($image);
}
}
$status = GetServerStatus('74.50.119.40',5555); // IP or Hostname Goes Here
?>

Matt`
July 9th, 2010, 10:52
Any errors? If it's just not showing anything, comment out the code that sets the content type headers so it'll show the errors.

Magestickown
July 9th, 2010, 10:58
Any errors? If it's just not showing anything, comment out the code that sets the content type headers so it'll show the errors.

It just always appears online even if it's off.
Only the registered members can see the link.

Twisted
July 9th, 2010, 13:02
Hey look, its my old friend from Cheatskape.
Remember me, its dog eats dog :)

O and first, lets break this down into little parts shall we?

1 - You didn't make this code of yours for 2 reasons.
A) Only the registered members can see the link.
B) -

2 - Your host doesn't allow Fsockopen, this is why it is displaying it as online all the time. Go find a paid host. You would know this if you actually wrote this code.
How do I know this?

Only the registered members can see the link.

And this is the server that this script reads from:
Only the registered members can see the link.

Magestickown
July 9th, 2010, 13:13
Hey look, its my old friend from Cheatskape.
Remember me, its dog eats dog :)

O and first, lets break this down into little parts shall we?

1 - You didn't make this code of yours for 2 reasons.
A) Only the registered members can see the link.
B) -

2 - Your host doesn't allow Fsockopen, this is why it is displaying it as online all the time. Go find a paid host. You would know this if you actually wrote this code.
How do I know this?

Only the registered members can see the link.

And this is the server that this script reads from:
Only the registered members can see the link.


I didn't really mean I wrote like that. He didn't define the function right so I defined it at the bottom; sorry for the misunderstanding.

-----------------------

I'm using a paid host. I have it here (Only the registered members can see the link.) too. I put it on the other host because my host only allows outgoing connections on port 80

Oh and how come you don't have any pages on your website? D:

EDIT:
Some freecsstemplate css's have been reported as to downloading malware on to visitors computer. So check that out.

Twisted
July 9th, 2010, 13:20
I didn't really mean I wrote like that. He didn't define the function right so I defined it at the bottom; sorry for the misunderstanding.

I'm using a paid host. I have it here (Only the registered members can see the link.) too. I put it on the other host because my host only allows outgoing connections on port 80

Oh and how come you don't have any pages on your website? D:

Its still in development.
Well either your paid host is screwed cause as that link I gave you, it works fine.
Misunderstanding tho, I'm sure there is a difference between "I wrote this" and "I'm using this".
:)

Magestickown
July 9th, 2010, 13:29
Whatever, I've been up for like 19 hours and I've been trying to sleep but I can't until I get this fixed. :D

I suppose I could just use ping instead of fsockopen. Better learning experience than just editing a script I found from Google.

Or find a host that supports fsockopen that is preferrably free. If I buy a different host (probably moving cause I fucking HATE my owners) what do you recommend. I'm looking for something cheap, but reliable as well.

I 'spose I could just use XAMMP on a VPS or dedicated server.

Twisted
July 9th, 2010, 13:32
You can be up for another 20 hours.
I do think its your host tho.
Even some paid hosts don't allow Fsock for security reasons.

Magestickown
July 9th, 2010, 13:35
I know. Yeah, fuckit. I'm going to just sneak it on to Clint's dedicated server lol.

Spear
July 9th, 2010, 13:38
Hope to see what the outcome is. >.>

Magestickown
July 9th, 2010, 13:41
*facepalm* didn't work. Geddamnit

Magestickown
July 9th, 2010, 13:42
Only the registered members can see the link.

I DIDN'T COMPLETELY EXPECT IT TO APPEAR ONLINE EVEN THOUGH IT'S OFF.

....-.-

Though it's connecting?.... When I look at my server at says it's connecting, then disconnecting.

Friss
July 9th, 2010, 17:08
Protip: With most paid hosts you have to ask them to allow you to do fsockopen on other ports

jamie
July 11th, 2010, 10:02
nope it works perfect. Thanks.

miiniikiller
August 8th, 2010, 00:29
Try This:



<?php
function GetServerStatus($site, $port) {
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if ($fp) {
$imagepath="on.png"; //ONLINE IMAGE LINK!
$image=imagecreatefrompng($imagepath);
header('Content-Type: image/png');
imagepng($image);
} else { //ONLINE Status
$imagepath="off.png"; //OFFLINE IMAGE LINK!
$image=imagecreatefrompng($imagepath);
header('Content-Type: image/png');
imagepng($image);
}
}
$status = GetServerStatus('74.50.119.40',5555); // IP or Hostname Goes Here
?>

Anthony`
August 8th, 2010, 00:43
Did you not read what was posted earlier, miiniikiller? He said fsockopen() is disabled on the host.