+ Reply to Thread
Results 1 to 4 of 4

Thread: Need help with PHP script

  1. #1
    cyberxzt's Avatar
    cyberxzt is offline Zine Tech cyberxzt is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Cheektowaga, New York
    Posts
    399

    Need help with PHP script

    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

  2. #2
    dharmil's Avatar
    dharmil is offline x10 Elder dharmil is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Avenel New Jersey
    Posts
    828

    Re: Need help with PHP script

    Here:
    PHP Code:
    <?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 by dharmil; 01-06-2007 at 12:43 PM.

  3. #3
    dest581 is offline x10 Lieutenant dest581 is an unknown quantity at this point
    Join Date
    Sep 2006
    Posts
    348

    Re: Need help with PHP script

    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.

  4. #4
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: Need help with PHP script

    Here is the way I have it setup on "status.x10hosting.com/status.php"

    First make an include, and put this in it:

    PHP Code:
    <?php

    $freeip 
    '66.232.109.231'// Assuming Free Server

    function serviceStatus($ip$port) {
       
    $handle = @fsockopen($ip$port$errno$errstr1);
       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 Code:
    $http serviceStatus($freeip80); // 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 Code:
    <?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$errstr30);
       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($image255000000);
    $green imagecolorallocate($image000100000);

    $font "arial.ttf";

    if (
    $status == 'Online') { $color $green; } else { $color $red; }
    imagettftext($image1001511$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 by Brandon; 01-07-2007 at 10:44 AM.
    Thanks,
    Brandon Long

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. Remove Documentation PHP Script
    By amr1991 in forum Scripts & 3rd Party Apps
    Replies: 5
    Last Post: 12-09-2006, 11:30 AM
  5. PHP login script
    By xunhandmex in forum Scripts & 3rd Party Apps
    Replies: 8
    Last Post: 05-26-2005, 07:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers