PDA

View Full Version : [PHP] Remote cPanel Bandwidth Viewer



BrandonTheG
April 22nd, 2007, 19:53
I am not sure if this goes here but:

Have you ever wanted to show how much bandwidth you have used?

Well do I have a solution for you...the Brandon's cPanel Bandwidth Checker!!


<?php

/*############################
Bandwidth From cPanel
Brandon's cPanel Bandwidth Checker!!!
Made by Brandon <brandon@x10hosting.com>
Support Info: http://www.blnetworks.net/showthread.php?p=197#post197
############################*/

// EDIT BELOW
$username = "username"; // cPanel Username
$password = "password"; // cPanel Password
$domain = "domain"; // cPanel Domain
$theme = "x"; // cPanel Theme



// DO NOT EDIT THIS CODE
ini_set("display_errors", "0");
$file = file_get_contents("http://$username:$password@$domain:2082/frontend/$theme/index.html") or die("<b>Critical Error, Please check your configuration</b>");
$string1 = strpos($file, "Bandwidth (this month)");
$file = substr($file,$string1);
$string2 = strpos($file, "Megabytes");
$length = strlen($file);
$take = $length - $string2;
$finally = substr($file,0,-$take);
$number = explode("<td class=\"index2\">", $finally);
$number = explode(" ",$number[1]);
$bandwidth = $number[0];


// START EDITING
/*
$bandwith is now the amount of bandwith you have used!
We are echoing it, but you can do whatever with it*/
echo $bandwidth;

?>

Edit the user name, password, domain, and theme...don't edit the do not edit unless you know what edits to edit!!!

You can remove "echo $bandwidth;" if you like, and include this in any script and add $bandwidth to the script were you want.

This was coded for an upcoming signature I am making, but I decided to release it.

If you find a bug, or me, I will fix it and release a new update:biggrin:

Also if you use it, i would appreciate a reply on how it works for you, maybe some rep, or just a thanks.

This is tested on x2 and x, if any others work please let me know.

d-j
April 23rd, 2007, 03:11
hmm.. actually the script try to login as usual, and try to search where's the 'bandwidth' string, and then use explode function..

nice.. :)

here a reference: http://www.josheli.com/vox/view_source.php?awstats.php

hope help you :)