46
HFS ~ HTTP File Server / Re: How to display current user in your hfs server using php?
« on: March 11, 2007, 04:20:36 PM »
by the way, here is the code that i used to make this work
this is the first section of my hfs template, with 2 easy changes
right after the footer part of the section, i added a hidden form wich will pass the info to the php+mysql, please note that in the form i call the file hfs-stats.php as action, here bellow is the content of the file:
and created a iframe with the results the file hfs-stats2.php here the content of the file:
and of course there is a database to store this info for future use os just to store the stats and access, but the possibilities are huge
this is the first section of my hfs template, with 2 easy changes
Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
%style%
</style>
<title>HFS %folder%</title>
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
%login-link%
%loggedin%
%upload-link%
<div id=folderlabel>folder</div>
<div id=folder>%folder%</div>
<div id=body>
%folder-comment%
%up%
%files%
</div>
<div id=footer>
<a href="http://www.rejetto.com/hfs/">HttpFileServer %version%</a>
<br />Servertime: %timestamp%
<br />Uptime: %uptime%
<br />Build-time: %build-time%
</div>
<div>
<form action="http://ledufe.no-ip.info/hfs/hfs-stats.php" method="post">
<input type=hidden name=hfsuserip value="%ip%">
<input type=hidden name=hfsusername value="%user%">
<input type=hidden name=hfsurl value="http://%host%%encoded-folder%">
<input type=hidden name=hfstime value="%timestamp%">
<input name=senddata type=submit value="Send Data to php">
</form>
<div>
<iframe name="HFS-PHP-Status-TRACKER" frameborder="1" width="auto" height="auto" marginheight="1" src="http://ledufe.no-ip.info/hfs/hfs-stats3.php" scrolling="auto"></iframe>
</body>
</html>
right after the footer part of the section, i added a hidden form wich will pass the info to the php+mysql, please note that in the form i call the file hfs-stats.php as action, here bellow is the content of the file:
Code: [Select]
<?php
echo "User IP: " . $_POST["hfsuserip"];
echo "<br>User Logged: " . $_POST["hfsusername"];
echo "<br>URL: " . $_POST["hfsurl"];
echo "<br>Time: " . $_POST["hfstime"];
echo "<br>Data Provided by LeDuFe HFS-Server.";
$username = "SQLUSERNAME";
$password = "SQLPASSWORD";
$hostname = "localhost";
$f_ip = $_POST["hfsuserip"];
$f_username = $_POST["hfsusername"];
$f_url = $_POST["hfsurl"];
$f_time = $_POST["hfstime"];
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to mysql");
print "<br>connected to mysql server<br>";
$selected = mysql_select_db("hfs",$dbh)
or die("Could not select HFS-DB");
if (mysql_query("insert into hfs_track (hfs_userip, hfs_username, hfs_url, hfs_time) VALUES ('$f_ip', '$f_username', '$f_url', '$f_time')")) {
print "successfully inserted record<br><a href='hfs-stats2.php'>Show Results</a><br><a href='#'' onclick='history.go(-1);return false;'>Back to HFS</a>";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>
and created a iframe with the results the file hfs-stats2.php here the content of the file:
Code: [Select]
<html>
<meta http-equiv="refresh" content="30">
<head>
<title>HFS PHP+MYSQL STATS - BY LeDuFe :-P</title>
</head>
<body>
<?php
$username = "SQLUSERNAME";
$password = "SQLPASSWORD";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to mysql");
print "<br>HFS-Server PHP+MySQL Statistics - Auto-Refresh every 30 seconds<br>";
echo date("d/m/Y h:i:sa", time());
print "<br><br>";
$selected = mysql_select_db("hfs",$dbh)
or die("Could not select HFS-DB");
$query = "SELECT hfs_userip, hfs_username, hfs_url, hfs_time FROM hfs_track WHERE hfs_time<'hfs_time' ORDER BY hfs_username, hfs_userip, hfs_time";
$result = mysql_query($query);
echo "<table>";
echo "<th>User IP Adress";
echo "<th>Logged Username";
echo "<th>URL";
echo "<th>Time";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo
"<tr><td align=left>".
"IP :{$row['hfs_userip']}".
"<td align=left>".
"USER NAME : {$row['hfs_username']}" .
"<td align=left>".
"URL : {$row['hfs_url']}" .
"<td align=left>".
"TIME : {$row['hfs_time']}";
}
echo "</table>";
mysql_close($dbh);
?>
</body>
</html>
and of course there is a database to store this info for future use os just to store the stats and access, but the possibilities are huge