Mobile Billing Meter
Posted on | March 14, 2009 | No Comments
Billing Meter bit.ly link or Billing Meter tech0x20 link.
This isn’t perfect. First of all, some connections are just too slow for a constant refresh rate of less than 20-30 seconds. Secondly, I think many mobile browsers have a refresh cut-off at which point they will ask you if you really want to keep refreshing.
The first page, index.php, allows you to enter parameters:
| PHP | | copy code | | ? |
| 01 | <?php |
| 02 | ?> |
| 03 | <h2>Billing Meter</h2> |
| 04 | <FORM ACTION="meter.php" METHOD="POST"> |
| 05 | <TABLE> |
| 06 | <TR> |
| 07 | <TD>Billing Rate per Hour</TD><TD><INPUT TYPE="TEXT" NAME="BILLINGRATE"/></TD> |
| 08 | </TR> |
| 09 | <TR> |
| 10 | <TD>Update Interval (in seconds)</TD><TD><INPUT TYPE="TEXT" NAME="REFRESHRATE"/></TD> |
| 11 | </TR> |
| 12 | <TR> |
| 13 | <TD>Press Submit to start the counter.</TD><TD><INPUT TYPE="SUBMIT" NAME="Submit"/></TD> |
| 14 | </TR> |
| 15 | </TABLE> |
| 16 | <INPUT TYPE="HIDDEN" NAME="STARTTIME" VALUE="-1"/> |
| 17 | </FORM> |
The second file, meter.php, does the display, calculation and refresh:
| PHP | | copy code | | ? |
| 01 | <?php |
| 02 | session_start(); |
| 03 | if(strlen($_POST["BILLINGRATE"])) |
| 04 | { |
| 05 | |
| 06 | $_SESSION["BILLINGRATE"] = (double)$_POST["BILLINGRATE"]; |
| 07 | $_SESSION["REFRESHRATE"] = (int)$_POST["REFRESHRATE"]; |
| 08 | if($_POST["STARTTIME"] == "-1") |
| 09 | { |
| 10 | $_SESSION["STARTTIME"] = time(); |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | echo "<meta http-equiv=\"refresh\" content=\"".$_SESSION["REFRESHRATE"]."\">"; |
| 15 | |
| 16 | $netseconds = time()-$_SESSION["STARTTIME"]; |
| 17 | $cost = sprintf("%10.2lf", round($_SESSION["BILLINGRATE"]*((double)$netseconds)/3600.0,2)); |
| 18 | ?> |
| 19 | <h2>Billing meter</h2> |
| 20 | <b>Time spent:</b> |
| 21 | <? |
| 22 | $time_counter = sprintf("%02d:%02d:%02d", $netseconds/3600, $netseconds / 60 % 60, $netseconds % 60); |
| 23 | ?> |
| 24 | <table><tr> |
| 25 | <? |
| 26 | for($i=0; $i<8; $i++) |
| 27 | { |
| 28 | echo "<td>".$time_counter[$i]."</td>"; |
| 29 | } |
| 30 | ?> |
| 31 | </tr></table> |
| 32 | <b>Your bill:</b> |
| 33 | <table><tr> |
| 34 | <td>$</td><? |
| 35 | for($i=0; $i<10; $i++) |
| 36 | { |
| 37 | if($cost[$i]==" ") |
| 38 | { |
| 39 | ?><td> </td><? |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | echo "<td>".$cost[$i]."</td>"; |
| 44 | } |
| 45 | } |
| 46 | ?> |
| 47 | </tr></table> |
| 48 |
Comments
Leave a Reply


















