View Full Version : Logging Text Files

11-05-2007, 02:08 AM
So I have logging on my website, and it works well. I wanted to modify it and add it to a contest page I made where a person can win something. It will show me their name and how many tickets they have entered. When I try it, the log works perfect. It keeps logging each time and shows the total amount.

The problem is it won't log for anyone else. It seems limited to just one person. So the log is contest_Fayt. It should show a list of logs from different users. So it would look something like this, (made up names)


and you should be able to click the link and see the results of that person. I can click mine and it shows everything. But again doesn't record anyone else. So here is the coding, which is suppose to make a log. If you need the whole function of the logging let me know.

$logdate = "contest_".$userrow["charname"];
$logpath = "./logs/contest".$userrow["charname"]."/";
if (!is_dir($logpath)) {
$logfile = $logpath.$logdate.".log";
$logcomments = "<br />--<b>".$userrow["charname"]."</b> Entered $tickets2 amount of tickets in the contest. ";
$logcomments .= $userrow["id"].",".$userrow["charname"]." on ".date("r");
$logcomments .= "\r\n";
$fp = fopen("$logfile", "a");
fwrite($fp, "$logcomments");
fclose ($fp);

11-05-2007, 03:15 AM
You need to trace $userrow["charname"] steps backward to see why it doesn't contain the different values like you think it does.

11-05-2007, 03:43 AM
It's weird because it saves the first textfile as contest_Fayt.log and I can view it perfectly fine.

11-05-2007, 12:26 PM
Start a session for all visitors. All visitors without a session are new

Here comes the PHP code:

if($_SESSION["logged"] != "yes")
$visitTime = date("r"); //Example: Thu, 21 Dec 2000 16:01:07 +0200

$logLine = "$visitTime - IP: $ip || User Agent: $agent || Page: $uri || Referrer: $ref\n";
$fp = fopen("visitorLog.txt", "a");
fputs($fp, $entry_line);
$_SESSION["logged"] = "yes";

11-05-2007, 05:39 PM
Max has jumped into the project for me. :thumbsup:

11-05-2007, 06:31 PM
Resolved ... for those following this post.