| 1 | <?php
|
|---|
| 2 | ###############################################################################
|
|---|
| 3 | ## Fancy Speed Test - Easily measure your upload and download speeds
|
|---|
| 4 | ## Home Page: http://www.brandonchecketts.com/speedtest/
|
|---|
| 5 | ## Author: Brandon Checketts
|
|---|
| 6 | ## File: results.php
|
|---|
| 7 | ## Version: 1.1
|
|---|
| 8 | ## Date: 2006-02-06
|
|---|
| 9 | ## Purpose: Display the speed test results in a meaningful way
|
|---|
| 10 | ## Save results to the database if enabled
|
|---|
| 11 | ###############################################################################
|
|---|
| 12 |
|
|---|
| 13 | require("common.php");
|
|---|
| 14 | ReadConfig("speedtest.cfg");
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | ## Save the results of this speedtest to the database, if enabled
|
|---|
| 18 | if ($config->{'database'}->{'enable'}) {
|
|---|
| 19 | $ip_matches = $config->{'database'}->{'ip_matches'};
|
|---|
| 20 | if ( (! $ip_matches) || ($ip_matches && preg_match("/$ip_matches/",$_SERVER['REMOTE_ADDR'])) ) {
|
|---|
| 21 | Debug("Saving to database");
|
|---|
| 22 | $dbh = mysql_connect(
|
|---|
| 23 | $config->{'database'}->{'host'},
|
|---|
| 24 | $config->{'database'}->{'user'},
|
|---|
| 25 | $config->{'database'}->{'password'}
|
|---|
| 26 | );
|
|---|
| 27 | $dbs = mysql_select_db( $config->{'database'}->{'database'}, $dbh);
|
|---|
| 28 | $table = $config->{'database'}->{'table'};
|
|---|
| 29 | $ip = $_SERVER['REMOTE_ADDR'];
|
|---|
| 30 | $upspeed = addslashes($_GET['upspeed']);
|
|---|
| 31 | $downspeed = addslashes($_GET['downspeed']);
|
|---|
| 32 | $sql = "
|
|---|
| 33 | INSERT INTO `$table`
|
|---|
| 34 | SET
|
|---|
| 35 | `ip_string` = '$ip',
|
|---|
| 36 | `ip` = INET_ATON('$ip'),
|
|---|
| 37 | `timestamp` = NOW(),
|
|---|
| 38 | `upspeed` = '$upspeed',
|
|---|
| 39 | `downspeed` = '$downspeed'
|
|---|
| 40 | ";
|
|---|
| 41 | mysql_query($sql,$dbh);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | ?>
|
|---|
| 48 | <html>
|
|---|
| 49 | <head>
|
|---|
| 50 | <title><?php print $config->{'general'}->{'page_title'}; ?> - Fancy Speed Test</title>
|
|---|
| 51 | <meta http-equiv="Expires" CONTENT="Fri, Jan 1 1980 00:00:00 GMT" />
|
|---|
| 52 | <meta http-equiv="Pragma" CONTENT="no-cache" />
|
|---|
| 53 | <meta http-equiv="Cache-Control" CONTENT="no-cache" />
|
|---|
| 54 | <link rel="stylesheet" href="style.css" />
|
|---|
| 55 | </head>
|
|---|
| 56 | <body>
|
|---|
| 57 |
|
|---|
| 58 | <?php
|
|---|
| 59 | if (file_exists("header.html")) {
|
|---|
| 60 | ## Include "header.html" for a custom header, if the file exists
|
|---|
| 61 | include("header.html");
|
|---|
| 62 | } else {
|
|---|
| 63 | ## Else just print a plain header
|
|---|
| 64 | print "<center>\n";
|
|---|
| 65 | }
|
|---|
| 66 | ?>
|
|---|
| 67 | <div id="speedtest_contents">
|
|---|
| 68 |
|
|---|
| 69 | <?php
|
|---|
| 70 |
|
|---|
| 71 | $bar_width = 400;
|
|---|
| 72 |
|
|---|
| 73 | $clean_down = CleanSpeed($_GET['downspeed']);
|
|---|
| 74 | $download_biggest = $_GET['downspeed'];
|
|---|
| 75 | print "<h2>Download Speed: $clean_down</h2>\n";
|
|---|
| 76 | ## Find the biggest value
|
|---|
| 77 | foreach ($config->{'comparisons-download'} as $key=>$value) {
|
|---|
| 78 | if ($value > $download_biggest) {
|
|---|
| 79 | $download_biggest = $value;
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 | ## Print a pretty table with a graph of the results
|
|---|
| 83 | print "<center><table>\n";
|
|---|
| 84 | foreach ($config->{'comparisons-download'} as $key=>$value) {
|
|---|
| 85 | $this_bar_width = $bar_width / $download_biggest * $value;
|
|---|
| 86 | print "<tr><td>$key</td><td>".CleanSpeed($value)."</td><td width=\"400\">\n";
|
|---|
| 87 | print "<img src=\"". $config->{'general'}->{'image_path'};
|
|---|
| 88 | print "bar.gif\" height=\"10\" width=\"$this_bar_width\" alt=\"$value kbps\" /></td></tr>\n";
|
|---|
| 89 | }
|
|---|
| 90 | $this_bar_width = $bar_width / $download_biggest * $_GET['downspeed'];
|
|---|
| 91 | print "<tr><td><b>Your Speed</b></td>\n";
|
|---|
| 92 | print "<td>$clean_down</td><td width=\"400\"><img src=\"";
|
|---|
| 93 | print $config->{'general'}->{'image_path'} . "bar.gif\" height=\"10\" width=\"$this_bar_width\"></td></tr>\n";
|
|---|
| 94 | print "</table>\n";
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | ## Don't display the upload stuff if we didn't get a speed to compare with
|
|---|
| 99 | if (isset($_GET['upspeed'])) {
|
|---|
| 100 | $clean_up = CleanSpeed($_GET['upspeed']);
|
|---|
| 101 | $upload_biggest = $_GET['upspeed'];
|
|---|
| 102 | print "<h2>Upload Speed: $clean_up</h2>\n";
|
|---|
| 103 | foreach ($config->{'comparisons-upload'} as $key=>$value) {
|
|---|
| 104 | if ($value > $upload_biggest) {
|
|---|
| 105 | $upload_biggest = $value;
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | print "<table>\n";
|
|---|
| 109 | foreach ($config->{'comparisons-upload'} as $key=>$value) {
|
|---|
| 110 | $this_bar_width = $bar_width / $upload_biggest * $value;
|
|---|
| 111 | print "<tr><td>$key</td><td>".CleanSpeed($value)."</td>\n";
|
|---|
| 112 | print "<td width='400'><img src=\"";
|
|---|
| 113 | print $config->{'general'}->{'image_path'} ."bar.gif\" height=\"10\" width=\"$this_bar_width\" alt=\"$value kbps\" /></td></tr>\n";
|
|---|
| 114 | }
|
|---|
| 115 | $this_bar_width = $bar_width / $upload_biggest * $_GET['upspeed'];
|
|---|
| 116 | print "<tr><td><b>Your Speed</b></td><td>$clean_up</td><td width='400'>";
|
|---|
| 117 | print "<img src=\"". $config->{'general'}->{'image_path'} ."bar.gif\" height=\"10\" width=\"$this_bar_width\"></td></tr>\n";
|
|---|
| 118 | print "</table>\n";
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | ?>
|
|---|
| 122 |
|
|---|
| 123 | <br /><br />
|
|---|
| 124 | <h2><a class="start_test" href="<?php echo $config->{'general'}->{'base_url'}; ?>/download.php">Test Again</a></h2>
|
|---|
| 125 | <div id="speedtest_credits">
|
|---|
| 126 | Powered by <a title="Brandon Checketts Fancy Speed Test" href="http://www.brandonchecketts.com/speedtest/" target="_new">Fancy Speed Test</a>
|
|---|
| 127 | </div>
|
|---|
| 128 | </div>
|
|---|
| 129 |
|
|---|
| 130 | <?php if (file_exists("footer.html")) { include("footer.html"); } ?>
|
|---|
| 131 |
|
|---|
| 132 | </body>
|
|---|
| 133 | </html>
|
|---|
| 134 |
|
|---|
| 135 | <?php
|
|---|
| 136 | ## Convert the raw speed value to a nicer value
|
|---|
| 137 | function CleanSpeed($kbps) {
|
|---|
| 138 | if ($kbps > 1024) {
|
|---|
| 139 | $cleanspeed = round($kbps / 1024,2) . " Mbps";
|
|---|
| 140 | } else {
|
|---|
| 141 | $cleanspeed = round($kbps,2). " kbps";
|
|---|
| 142 | }
|
|---|
| 143 | return $cleanspeed;
|
|---|
| 144 | }
|
|---|
| 145 | ?>
|
|---|
| 146 |
|
|---|