Skip to content

Instantly share code, notes, and snippets.

@chaseoes
Last active Sep 18, 2016
Embed
What would you like to do?
Display stats provided by the TF2 Bukkit plugin.
<?php
// MySQL Information
$database_hostname = 'localhost';
$database_username = 'username';
$database_password = 'password';
$database_name = 'my_database';
$database_port = '3306';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta -->
<title>TF2 Stats</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta name="author" content="chaseoes">
<!-- Styles -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<style type="text/css">
body {
margin: 150px;
margin-top: 80px;
}
</style>
</head>
<body>
<h1>TF2 Stats</h1>
<?php
$sortby = 'kills';
$limit = '50';
$order = 'DESC';
if (isset($_GET["sort"])) {
$sortby = $_GET["sort"];
}
if (isset($_GET["limit"])) {
$limit = $_GET["limit"];
}
if (isset($_GET["order"])) {
$order = $_GET["order"];
}
$con = mysql_connect($database_hostname . ":" . $database_port, $database_username, $database_password);
if (!$con) {
die('Could not connect to database.');
}
echo "Stats page automatically generated for the <a href='http://dev.bukkit.org/server-mods/team-fortress-2'>TF2</a> plugin, currently sorted by " . $sortby . ". <hr />";
mysql_select_db($database_name, mysql_connect($database_hostname . ":" . $database_port, $database_username, $database_password));
$result = mysql_query("SELECT * FROM players ORDER BY CONVERT(" . $sortby . ", UNSIGNED INTEGER) " . $order . " LIMIT " . $limit);
echo "<table class='table table-hover table-bordered'>
<tr>
<th>Username</th>
<th>Kills</th>
<th>Highest Killstreak</th>
<th>Points Captured</th>
<th>Games Played</th>
<th>Red Team Count</th>
<th>Blue Team Count</th>
<th>Time Ingame</th>
<th>Games Won</th>
<th>Arrows Fired</th>
<th>Deaths</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['highest_killstreak'] . "</td>";
echo "<td>" . $row['points_captured'] . "</td>";
echo "<td>" . $row['games_played'] . "</td>";
echo "<td>" . $row['red_team_count'] . "</td>";
echo "<td>" . $row['blue_team_count'] . "</td>";
echo "<td>" . $row['time_ingame'] . "</td>";
echo "<td>" . $row['games_won'] . "</td>";
echo "<td>" . $row['arrows_fired'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<p style="float: left;"><hr /><span class="muted">TF2 stats page created by <a href="http://github.com/chaseoes">chaseoes</a> for the <a href="http://dev.bukkit.org/server-mods/team-fortress-2/">TF2</a> plugin.</p>
</body>
</html>
@jamietech

This comment has been minimized.

Copy link

@jamietech jamietech commented Jan 19, 2013

Oops! You forgot to escape input by users.

@SamORichards

This comment has been minimized.

Copy link

@SamORichards SamORichards commented Apr 30, 2013

wait so is this broken

@sasuke200

This comment has been minimized.

Copy link

@sasuke200 sasuke200 commented May 6, 2013

lol, someone code use sql injection easy on this code... should of done preg_match so then if it does not match numbers to die().

@Permanently

This comment has been minimized.

Copy link

@Permanently Permanently commented Feb 17, 2016

Thanks! ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment