Hi All,
I have this page that I'm plonking into my PHPnuke site... It lists who recently visited the site, and how long ago it was... nice feature I think.
It works fine, however, the name of the person should link to their profile page - like this -
http://mydomain.com/user.php?op=userinfo&uname=sonicsnail
but its appearing as
http://mydomain.com/user.php?op=userinfo&uname=
so it takes you to a blank page.
Now I'm no expert with PHP, but I get the feeling that theres a syntax error in this bit of the code....
$content .= "<font class=tiny><a href=\"user.php?op=userinfo&uname=\"".$uname."\">".$uname."</a>:";
Also, I think that $uname should really be $username ??
here's the whole thing... hope someone can help me here...
quote:
<?
// Michael Yarbrough
// opedog@comediccadavers.com
// http://www.comediccadavers.com/
// PHP-Nuke 5.1 Blocks version by Thiago Campos aka Mr. Hemp (mrhemp@amigoz.org)
global $cookie, $prefix, $currentlang;
if(file_exists("language/lastseen/lastseen-$currentlang.php")) {
include("language/lastseen/lastseen-$currentlang.php");
}
else {
include("language/lastseen/lastseen-english.php");
}
$numusers = 20;
$username = $cookie[1];
mysql_query("CREATE TABLE IF NOT EXISTS $prefix"._lastseen." (id INT (15) not null AUTO_INCREMENT, username TEXT not null, date INT(15) not null, ip CHAR(50), PRIMARY KEY (id), UNIQUE (id))");
if (isset($username)) {
$ip = getenv("REMOTE_HOST");
if (empty($ip)) {
$ip = getenv("REMOTE_ADDR");
}
$result = mysql_query("SELECT * FROM $prefix"._lastseen." WHERE username = \"$username\"");
if (mysql_num_rows($result) > 0) {
mysql_query("UPDATE $prefix"._lastseen." SET date = " . time() . " WHERE username = \"$username\"");
} else {
mysql_query("INSERT INTO $prefix"._lastseen." VALUES (\"\", \"$username\", ".time().", \"".$ip."\")");
}
}
$content = "";
$result = mysql_query("SELECT username, date FROM $prefix"._lastseen." ORDER BY date DESC");
while (list($uname, $date) = mysql_fetch_row($result)) {
if ($uname != $username) {
$realtime = time() - $date;
$dont = false;
// how many days ago?
if ($realtime >= (60*60*24*2)) { // if it's been more than 2 days
$days = floor($realtime / (60*60*24));
$dont = true;
} else if ($realtime >= (60*60*24)) { // if it's been less than 2 days
$days = 1;
$realtime -= (60*60*24);
}
if (!$dont) {
// how many hours ago?
if ($realtime >= (60*60)) {
//$content .= " ($realtime) ";
$hours = floor($realtime / (60*60));
$realtime -= (60*60*$hours);
}
// how many minutes ago?
if ($realtime >= 60) {
$mins = floor($realtime / 60);
$realtime -= (60*$mins);
}
// just a little precation, although I don't *think* mins will ever be 60...
if ($mins == 60) {
$mins = 0;
$hours += 1;
}
}
$content .= "<font class=tiny><a href=\"user.php?op=userinfo&uname=\"".$uname."\">".$uname."</a>:";
if ($dont) {
$content .= " ".$days." "._LASTSEENDAYS."";
} else {
if ($days > 0) {
$content .= " ".$days." "._LASTSEENDAY."".(($hours == 0 && $mins == 0)?("") ","));
}
if ($hours > 0) {
$content .= " ".$hours." ".(($hours > 1)?(""._LASTSEENHOURS."") ""._LASTSEENHOUR."")).(($mins == 0)?("") ","));
}
if ($mins > 0) {
$content .= " ".$mins." ".(($mins > 1)?(""._LASTSEENMINUTES."") ""._LASTSEENMINUTE.""))."";
} else { // less than a minute
$content .= " ".$realtime." "._LASTSEENSECONDS."";
}
}
$content .= " "._LASTSEENAGO."</font><br>";
$days = 0;
$hours = 0;
$mins = 0;
$dont = false;
}
}
$content .= "";
?>
Thanks!
::Edit to disable smilies!::
[This message has been edited by sonicsnail (edited 09-30-2001).]