Can you tell me why smarty pants?

Discussion in 'PHP' started by ScoTech, Jul 26, 2008.

  1. #1
    Why do I see repeat entrys in the log.txt file created by the redirect script found below?

    i.e.
    July 25, 2008, 21:38:13

    216.254.66.xxx
    <--------------------->
    July 25, 2008, 21:38:18

    216.254.66.xxx
    <--------------------->
    July 25, 2008, 21:38:55

    216.254.66.xxx
    <--------------------->
    July 25, 2008, 21:38:56

    216.254.66.xxx
    <--------------------->


    <?php
    
    $redirectURL = "http://xxxxx.xxxxx.hop.clickbank.net/?tid=xxxxx";
    
    $referer = $_SERVER['HTTP_REFERER'];
    
    $remaddr = $_SERVER['REMOTE_ADDR'];
    
    $today = date("F j, Y, H:i:s");
    
    $file = fopen("log.txt","a");
    
    fwrite($file, $today . "\r\n");
    
    fwrite($file, $referer . "\r\n");
    
    fwrite($file, $remaddr . "\r\n");
    
    fwrite($file, "<--------------------->\r\n");
    
    fclose($file);
    
    ?>
    
    <html>
    
    <head>
    
    </head>
    
    <body>
    
    <script type="text/javascript">
    
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    
    </script>
    
    <script type="text/javascript">
    
    var pageTracker = _gat._getTracker("UA-xxxxxxx-xx");
    
    pageTracker._initData();
    
    pageTracker._trackPageview();
    
    </script>
    
    <!- html redirect ->
    
    <META HTTP-EQUIV="Refresh" CONTENT="0; URL=<?php echo $redirectURL ?>"
    
    </body>
    
    </html>
    PHP:
     
    ScoTech, Jul 26, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    It seems that they are in two groups (i.e. user has hit the 'back' button and clicked again). Have you tested your script against double clicking?

    Jay
     
    jayshah, Jul 26, 2008 IP
  3. optic

    optic Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $file = fopen("log.txt","a");
    The second param of fopen "a" says
    "Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. "

    That means it is going to append everything you write to the end of the file. It sounds like you want to have the file created new every time the script loads. If that is so you want "w" for the second param.


    Hope this helps.
     
    optic, Jul 26, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    That is completely incorrect. If you use a different mode (i.e. w), you will loose all previous entries. 'a' is the correct mode.

    Jay
     
    jayshah, Jul 26, 2008 IP
  5. optic

    optic Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My statement is correct. "a" appends everything you write to the end of the file. Read the docs on php.net. The original post states repeat entries in the log. I was simply pointing out that "a" is going to append everything you write to the end of the file, so that one file is going to grow and continue to grow. If you look at the log sample posted. The timestamps are different so this is a matter of the data being appended to the end of the file.
     
    optic, Jul 26, 2008 IP
  6. ScoTech

    ScoTech Peon

    Messages:
    310
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, I want the file to grow, and I did not think about back button, or double clicks, although it has done it to me when I know I single clicked.

    I guess I just wanted to make sure my script is successfully getting people to the publisher's page, while still writing to my log and google analytics. The reason for the log is so I can change the redirect based on the referring URL, and I just wanted to see what the referring URL looked like from different sources, like ezine articels, yahoo answers, etc...When I saw the repeat entries, most in the space of a second, I just wanted to make sure internet explorer or something else isn't preventing my hoplink from happening. Thanks for any advice you guys can give me!
     
    ScoTech, Jul 26, 2008 IP