All pastes #942908 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-14 20:44 UTC
rendered paste body
<?php
if (!defined('in_tt-admin')) {
	die ("Hacking Attempt!");
}

?>
				<div class="page-block">
					<div class="header">
						<h2>Site Analytics</h2>
					</div>
					<div class="contents">
						<?php
						$result = $db->query("SELECT * FROM `".$config->database['prefix']."browsers` ORDER BY id"); // Query.
						$total = mysql_num_rows($result); // Total rows.
						
						// Define some variables that will do a lot of the math.
						$msie = 0;
						$firefox = 0;
						$opera = 0;
						$other = 0;
						
						// Other string variables
						$msie_string = "MSIE";
						$firefox_string = "Firefox";
						$opera_string = "Opera";
						
						// Here we go ... gotta count up the tally!
						while($user = mysql_fetch_array($result)) {
							$check = strpos($user['agent'], $msie_string);
							if ($check === true) {
								$msie++;
							} else {
								$check = strpos($user['agent'], $firefox_string);
								if ($check === true) {
									$firefox++;
								} else {
									$check = strpos($user['agent'], $opera_string);
									if ($check === true){
										$opera++;
									} else {
										$other++;
									}
								}
							}
						}
						
						// Now we do some tough mathmatical calculations.
						$msie = ceil($total/$msie);
						$firefox = ceil($total/$firefox);
						$opera = ceil($total/$opera);
						$other = ceil($total/$other);
						
						// Now we echo the data!
						echo "<b>".$msie."%</b> of visitors are using Microsoft Internet Explorer<br />";
						echo "<b>".$firefox."%</b> of visitors are using Mozilla Firefox<br />";
						echo "<b>".$opera."%</b> of visitors are using Opera<br />";
						echo "<b>".$other."%</b> of visitors are using other browsers";
						
						?>
					</div>
				</div>