+ Reply to Thread
Results 1 to 3 of 3

Thread: php bandwidth used script

  1. #1
    gtakiller is offline x10Hosting Member gtakiller is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    1

    php bandwidth used script

    i will show how to make a bandwidth used bar

    step 1 make a new php file eg bandwidth.php

    step 2 add
    PHP Code:
    <?php
    $sAuth 
    base64_encode("username:pass");  //your username:password for cpanel
    $domain "www.domain.com"//domain of your website
    $total 10000//amount of bandwidth you get in mb
    $cpanelport 2082//port of cpanel default is 2082

    $hSocket fsockopen($domain,$cpanelport);
    if(!
    $hSocket) {
        die(
    "Connection Failed.");
    } else {
        
    fputs($hSocket"POST /frontend/x3/index.html HTTP/1.0\r\n"); //based on the x3 theme of cpanel
        
    fputs($hSocket"Host: $domain\r\n");
        
    fputs($hSocket"Authorization: Basic $sAuth\r\n");
        
    fputs($hSocket"Connection: Close\r\n");
        
    fputs($hSocket"\r\n");
        
    $printNext false;
        
    $bw 0;
        while(!
    feof($hSocket)) {
            
    $response fgets($hSocket4096);
            
    $response strip_tags($response);
            
    $response addslashes($response);
            
    $pos strpos($response'Monthly Bandwidth Transfer');
            if(
    $pos 0) {
                
    $response explode("/"$response);
                
    $t array_pop($response);
                
    $t array_shift($response);
                
    $response explode("Monthly Bandwidth Transfer"$response[0]);
                
    $t array_shift($response);
                break;
            }
        }
    }
    fclose($hSocket);
    header("Content-type: image/png");
    if(!
    $total) {
        
    $total 100;
    }
    function 
    drawBar($bandwidth$total) {
        
    //$total=$bandwidth+3.14;
        
    $barWidth 200//set this for bar width
        
    $barHeight 16//set this for bar height
        
    $fontSize 2//HTML Font Size
        
    $imgWidth $barWidth//Keep this
        
    $imgHeight $barHeight//Keep this
        
    $image imagecreate($imgWidth$imgHeight);
        
    $back ImageColorAllocate($image255255255);
        
    $border ImageColorAllocate($image000);
        
    $fill ImageColorAllocate($image2551390);
        
    $text ImageColorAllocate($image071255);
        
    ImageFilledRectangle($image00$barWidth$barHeight 1$back);
        
    $adjBar = (float)(($bandwidth $total) * ($barWidth 1));
        
    ImageFilledRectangle($image11$adjBar, ($barHeight 2), $fill);
        
    ImageRectangle($image00$barWidth 1$barHeight 1$border);
        
    $PerCent = (float)(($bandwidth $total) * 100);
        
    $myText = (string )("Usage: " round($bandwidth2) . "MB/" $total "MB");
        
    $textLength strlen($myText);
        
    $textLeft = (($barWidth 1) / 2) - (($textLength 2) * imagefontwidth($fontSize));
        
    $textTop = ($barHeight imagefontheight($fontSize)) / 2;
        
    ImageString($image$fontSize$textLeft$textTop$myText$text);
        
    imagePNG($image);
        
    imagedestroy($image);
    }
    drawBar((float)$response[0], $total);
    ?>
    step 3 change $sAuth = base64_encode("username:pass"); $domain = "www.domain.com"; line to your info

    step 4 save and upload

    to add the image to html flie just use
    <img src='bandwidth.php' alt='Bandwidth Usage' />"



    Last edited by gtakiller; 05-26-2009 at 11:37 AM. Reason: added img

  2. #2
    cvrshop is offline x10Hosting Member cvrshop is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    7

    Re: php bandwidth used script

    Great ! Thanks for your teaching!:lockd:

  3. #3
    nirajkum is offline x10 Sophmore nirajkum is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    161

    Re: php bandwidth used script

    that was really good and useful script will use it in my site ....

+ Reply to Thread

Similar Threads

  1. Photo-Graffix Gallery Php Script...
    By millart in forum Free Hosting
    Replies: 7
    Last Post: 09-17-2008, 11:42 AM
  2. foward mail to a php script
    By ruicos in forum Programming Help
    Replies: 3
    Last Post: 09-13-2008, 07:55 AM
  3. Cannot get php script to work
    By avidgamer in forum Free Hosting
    Replies: 3
    Last Post: 09-03-2008, 04:35 PM
  4. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  5. RSS to HTML PHP Script (FREE)
    By unmanaged in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 02-21-2008, 04:44 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