Jump to content


Php internet usage counter


4 replies to this topic

#1 Rory

    Jedi In Training

  • Members
  • PipPip
  • 378 posts
  • Gender:Male
  • Location:Hastings, Hawkes bay, New Zealand
  • Interests:Php, Html, Css, Javascript, ASP.NET, Photoshop, soccer, rigby, cricket, viticulture, Ruby#, C#, AJAX.

Posted 09 February 2007 - 01:42 PM

I am trying to build a php internet usage counter for personal use. It would be like a proxy but all it needs to do is count how many megabytes have been used in that particular session.

I would then have a little toolbar at the bottom with a link which I hover the mouse over to find out how many mb I have used in that session. The only part I am not sure about is how to count the megabytes, which is pretty much the main part of the script. :D

I looked on google but I have been unsuccessful in finding any function or anything similar to record transferred data. It is no problem if it counts bytes only and I have to divide the number to turn it into megabytes, that is of course easy. Any help with this will be seriously appreciated. ;)

EDIT: I am also open to combining other languages with php eg. javascript if that is required to achieve what I'm trying to do.

Edited by Rutilus Rex, 09 February 2007 - 02:53 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 09 February 2007 - 03:12 PM

As far as I know, PHP wouldn't be able to do something like that unless you were to use it to grab file sizes of all files your browser encountered. This of course would be impossible due to images, stylesheets, and all attached files; plus this isn't the way PHP works, as you'd have to feed it all through your localhost (localhost/tracker.php?url=www.site.com), which wouldn't let you follow links properly unless you were to use regex and change links like proxies do.
Basically you're looking for the wrong language.

This would be a job for VB or C++ or some other platform language you could plug directly into your browser as an extension or plug-in. Look on www.mozilla.com and search the extensions; you just might be able to find an extension taht already does this, or atleast find information on how to make your own.

#3 Rory

    Jedi In Training

  • Members
  • PipPip
  • 378 posts
  • Gender:Male
  • Location:Hastings, Hawkes bay, New Zealand
  • Interests:Php, Html, Css, Javascript, ASP.NET, Photoshop, soccer, rigby, cricket, viticulture, Ruby#, C#, AJAX.

Posted 09 February 2007 - 03:27 PM

Ok thanks demon, I'll check out mozilla's website. :D

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 February 2007 - 11:16 PM

PHP would not be ideal for something like this, but with some preg_* functions and output buffering it may be possible.

Simply have output buffering store all of the output of your site into a single variable, then run through it with preg_match_all() looking for things like img, link, and script tags that import something, and tally up the sizes of everything.

In my experience, one character would equal a byte, so, count() could return the rough size of everything. Keep in mind though, it wouldn't be exact, just close.

#5 Rory

    Jedi In Training

  • Members
  • PipPip
  • 378 posts
  • Gender:Male
  • Location:Hastings, Hawkes bay, New Zealand
  • Interests:Php, Html, Css, Javascript, ASP.NET, Photoshop, soccer, rigby, cricket, viticulture, Ruby#, C#, AJAX.

Posted 10 February 2007 - 02:12 PM

Thanks rc, might give that a go! :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users