Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 09-23-2009, 11:12 PM   #1
The Wandering Businessman
War Room Member
 
Chris Ramsey's Avatar
 
Join Date: Jan 2008
Location: The Globe
Posts: 1,209
Thanks: 142
Thanked 755 Times in 196 Posts
Default 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 is offline   Reply With Quote
Old 09-23-2009, 11:17 PM   #2
The Wandering Businessman
War Room Member
 
Chris Ramsey's Avatar
 
Join Date: Jan 2008
Location: The Globe
Posts: 1,209
Thanks: 142
Thanked 755 Times in 196 Posts
Default Re: Help me debug a PHP script

Nevermind. I figured it out right after I posted. It was being called twice.

Chris Ramsey is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
debug, php, script

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 09:15 PM.