Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Logging Text Files

    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)

    contest_Mark
    contest_Henry
    contest_William
    contest_sarah

    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.

    Code:
    $logdate = "contest_".$userrow["charname"];
            $logpath = "./logs/contest".$userrow["charname"]."/";
    			if (!is_dir($logpath)) {
    		 	@mkdir($logpath,0777);
           	 	@chmod($logpath,0777);
           		}
    		$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);

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need to trace $userrow["charname"] steps backward to see why it doesn't contain the different values like you think it does.

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    It's weird because it saves the first textfile as contest_Fayt.log and I can view it perfectly fine.

  • #4
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Start a session for all visitors. All visitors without a session are new

    Here comes the PHP code:

    session_start();
    if($_SESSION["logged"] != "yes")
    {
    $agent = $_SERVER['HTTP_USER_AGENT'];
    $uri = $_SERVER['REQUEST_URI'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $ref = $_SERVER['HTTP_REFERER'];
    $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);
    fclose($fp);
    $_SESSION["logged"] = "yes";
    }
    ?>

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Max has jumped into the project for me.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Resolved ... for those following this post.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •