Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Help me debug a PHP script (https://www.warriorforum.com/programming/127506-help-me-debug-php-script.html)

Chris Ramsey 23rd September 2009 10:12 PM

Help me debug a PHP script
 
I'm working on a short script to write some information to a text file.

First of all - here's the script.

Code:

$time = time();
        $ip = $_SERVER['REMOTE_ADDR'];
        $refer = $_SERVER['HTTP_REFERER'];
        if ($refer == "") { $refer = "No Referrer available."; }
        $write = "||$refer^$ip^$time";
        $filename = "stats.txt";

        if($flag == false) { // if the file doesn't exist
                $handle = fopen($filename, 'w') or die("can't open file");
                fwrite($handle, $write);
                fclose($handle);
        } else { //if the file already exists
                //write to file
                $handle = fopen($filename, 'a') or die("can't open file");
                fwrite($handle, $write);
                fclose($handle);
        }

Now, when the script runs, it writes to the file twice and I'm not sure why. Here's a quick faux script.

Gather information -> Does the file already exist? -> (No) Create empty file (Yes) Append gathered information to the end of the file

Can anyone see where this is going wonky? I'm not seeing it here and have a feeling the script is being called twice somehow.

Chris Ramsey 23rd September 2009 10:17 PM

Re: Help me debug a PHP script
 
Nevermind. I figured it out right after I posted. It was being called twice.


All times are GMT -6. The time now is 04:16 AM.