Need help with PHP script

cyberxzt

Zine Tech
Messages
798
Reaction score
0
Points
0
Hello, I want to know how to make a PHP script that checks an ip and port that is specified within itself and then displays a picture for offline or online.

I want it to be able to post it as a normal picture.

I know its really easy to do, i just cant do php scripting.

THX
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
Here:
PHP:
<?php
function nowww($text) {
$word = array(
"http://" => "",
"www." => "",
);
foreach ($word as $bad => $good) {
$text = str_replace($bad, $good, $text);
}
$oldurl = explode("/", $text);
$newurl = $oldurl[0];
$text = "$newurl";
$text = strip_tags(addslashes($text));
return $text;
}
$ip = "0.0.0.0";
$port = "80";
$checkup = "$ip";
$status = nowww("$checkup");
$check = @fsockopen($status, $port);
$onlineImage = "<img scr=\"online.gif\">";
$offlineImage = "<img scr=\"offline.gif\">";
if ($check) {
echo "Status For ".$status.": ".$onlineImage."";
else {
echo "Status For ".$status.": ".$offlineImage."";
}
?>
 
Last edited:

dest581

New Member
Messages
348
Reaction score
0
Points
0
that code is good, but it might not be a good idea to remove the www. as some sites still only work with it. Of course, I've seen only 2.
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Here is the way I have it setup on "status.x10hosting.com/status.php"

First make an include, and put this in it:

PHP:
<?php

$freeip = '66.232.109.231'; // Assuming Free Server

function serviceStatus($ip, $port) {
   $handle = @fsockopen($ip, $port, $errno, $errstr, 1);
   if (!$handle) {
      $string = 'false';
   } else {
      $string = 'true';
      @fclose($handle);
   }
   return $string;
}

?>

Then include this to any PHP you want it to be shown on. Next put this code in

PHP:
$http = serviceStatus($freeip, 80); // Chane 80 to the port, and http to the service or port.

// Display a nice output

if ($http == 'true') { echo '<span class="online">Online</span>';      ///Chate $http to whatever you change it to above.
} else { echo '<span class="offline">Offline</span>';}

Change the class to w/e, it can even be a fond too... I see this way easier, but thats my opinion.

Here is how to make an image

PHP:
<?php

ob_flush();
$ip = ''; // Set this as IP
// $port = $_GET['port']; //  <-- Use this for ?port=portnumber
$port = ''; // <-- Set this for static port

function serviceStatus($ip, $port) {
   $handle = @fsockopen($ip, $port, $errno, $errstr, 30);
   if (!$handle) {
      $string = 'Down';
   } else {
      $string = 'Online';
      @fclose($handle);
   }
   return $string;
}
header("Content-type: image/png");

$status = serviceStatus($ip, $port);

$image = imagecreatefrompng('status.png');



$red = imagecolorallocate($image, 255, 000, 000);
$green = imagecolorallocate($image, 000, 100, 000);

$font = "arial.ttf";

if ($status == 'Online') { $color = $green; } else { $color = $red; }
imagettftext($image, 10, 0, 15, 11, $color, $font, $status);

      imagepng($image);
      imagedestroy($image);



ob_end_flush();

?>

Also you need status.png and arial.tff <-- Make sure both these files are in same dir as the php script.

Set $ip as the server ip, and then say you name it "status.php", run "status.php?port=80" to check port 80, and it will diplay up and down.

You can change the backround image by changing image.png
 
Last edited:
Top