Problemer med PHP "hvor mange on-line" script?
Hej Eksperter,Jeg har et problem med et PHP script der skal vise hvor mange der er on-line på mit websted.
jeg får følgende fejl i browseren:
Warning: main(): Unable to access /web/www/frac/usersinclude.online.php in /web/www/frac/users/foxmulder58/index.php on line 1
Warning: main(/web/www/frac/usersinclude.online.php): failed to open stream: No such file or directory in /web/www/frac/users/foxmulder58/index.php on line 1
Warning: main(): Failed opening '/web/www/frac/usersinclude.online.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /web/www/frac/users/foxmulder58/index.php on line 1
Fatal error: Call to undefined function: online_addcount() in /web/www/frac/users/foxmulder58/index.php on line 3
<--------------------- include.online.php --------------------->
<?php
// ONLINE_FILE = Placering af log-file fra document-root.
// ONLINE_TIME = Antal sekunter en bruger er på online-listen.
define("ONLINE_FILE", "include.online.log");
define("ONLINE_TIME", "60");
?>
<?php
// Function som returner tid og dato i timestamp-format.
// Bruges sammen med PHP´s date() function.
function online_date_value() {
$values = getdate();
return $values[0];
}
?>
<?php
// Function som returner en givet IP-adresse hvor de sidste
// nummer ikke er med. (For at beskytte brugeren.)
function online_trimip($String) {
$intDot = strrpos($String, ".");
if ($intDot) {
return substr($String, 0, $intDot).".--";
} else {
return $String;
}
}
?>
<?php
// Function som tilføjer en givet bruger til online-listen.
// Her kan man definer sidens title og brugernavn.
function online_addcount($PageTitle = "", $UserName = "") {
$strIP = $_SERVER["REMOTE_ADDR"];
$strPage = $_SERVER["PHP_SELF"];
$strDate = online_date_value();
if ($UserName) {
$strUser = $UserName;
} else {
$strUser = $strIP;
}
if ($PageTitle) {
$strTitle = $PageTitle;
} else {
$strTitle = $strPage;
}
if (file_exists($_SERVER["DOCUMENT_ROOT"].ONLINE_FILE)) {
$arrFile = file($_SERVER["DOCUMENT_ROOT"].ONLINE_FILE);
}
if (is_array($arrFile)) {
foreach($arrFile as $strLine) {
$arrExp = explode("*", $strLine);
if ($strDate < ($arrExp[0] + ONLINE_TIME)) {
if ($strUser == $arrExp[1] || $strIP == $arrExp[1]) {
$arrExp[0] = $strDate;
$arrExp[1] = $strUser;
$arrExp[2] = $strPage;
$arrExp[3] = $strTitle;
$blnUpdate = TRUE;
}
$strData .= $arrExp[0]."*".$arrExp[1]."*".$arrExp[2]."*".$arrExp[3]."*\r\n";
$Count += +1;
}
}
}
if (!$blnUpdate) {
$strData .= $strDate."*".$strUser."*".$strPage."*".$strTitle."*\r\n";
$Count += +1;
}
$fp = fopen($_SERVER["DOCUMENT_ROOT"].ONLINE_FILE, "w+");
fwrite($fp, $strData);
fclose($fp);
return $Count;
}
?>
<?php
// Function som viser online-listen, den skal bruges sammen med
// en html-table. Her kan man definer TdColor og DateFormat.
function online_create_td_table($TdColor = "", $DateFormat = "H:i") {
if (file_exists($_SERVER["DOCUMENT_ROOT"].ONLINE_FILE)) {
$arrFile = file($_SERVER["DOCUMENT_ROOT"].ONLINE_FILE);
}
if (is_array($arrFile)) {
rsort($arrFile);
foreach($arrFile as $strLine) {
$arrExp = explode("*", $strLine);
if ($TdColor) {
$c += +1;
if (($c % 2) == 1) {
$td_color = ' bgcolor="'.$TdColor.'"';
} else {
$td_color = "";
}
}
echo "<tr>";
echo "<td".$td_color.">".date($DateFormat, $arrExp[0])."</td>";
echo "<td".$td_color.">".online_trimip($arrExp[1])."</td>";
echo "<td".$td_color.">".'<a href="'.$arrExp[2].'">'.$arrExp[3]."</a></td>";
echo "</tr>";
}
}
}
?>
<------------------------- index.php------------------------>
<?php include($_SERVER["DOCUMENT_ROOT"]."include.online.php");?>
<?php
$user_count = online_addcount("Online side");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>::.Mads Nørgård Sørensen.::</title>
<link rel="stylesheet" type="text/css" href="default.css" media="screen,projection"
title="Default" />
</head>
<body>
<div class="bodywrap">
<div id="content">
<table><tr><td><?php include("flash/flashbanner.txt"); ?></td></tr></table>
<table<tr><td><?php include("flash/nav.txt"); ?></td></tr></table>
<?php include("tabel.txt"); ?><p/>
<table><tr><td><?php echo $user_count;?></tr></td></table>
</div>
</body>
</html>
