PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 29th, 2002, 07:20 AM
rxsid rxsid is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 86 rxsid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Why won't this fopen() or file() work?

Hi all,
I'm trying to creat a text login file. Problem is that sometimes the previously written user|time is not retained, and sometime the time is truncated and place on a newline as a new entry.
This code should just open the file, build the current array based on appropriate amount of lapsed time, and then put the current user in the file along with the array.

$tnow=date("Gi");
$in=file("TestingIN.txt");

$flag=0;
$cnt = count($in);
for ($x=0;$x < $cnt;$x++) {
list($u_in,$time_in)=split("|",$in[$x]);

if ("$u" != "$u_in") { //If they dont compare.
if ($time_in>$tnow) {
$tnow1=$tnow+240; //Compensate for different day. Midnight is 000!!
if (($tnow1-$time_in) < 5) { //KEEP if less 5 min.
$old_in[]=$in[$x];
$flag++;
} else {
//Do Nothing
}
} elseif ($time_in < $tnow) {
if (($tnow - $time_in) < 5 ) {
$old_in[]=$in[$x];
$flag++;
} else {
//Do Nothing
}
} else {
//Do Nothing
}
}//END if they dont compare.
}

$newinfo="$u|$tnown";

$in2=fopen("TestingIN.txt","w");

$fp=fputs($in2,$newinfo, 40);

for($y=0;$y < $flag;$y++) {
$fp=fputs($in2, $old_in[$y], 40);
}
fclose($in2);

Any ideas why this won't work as stated?

Thanks in advance!

Reply With Quote
  #2  
Old August 29th, 2002, 05:47 PM
guyer guyer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN USA
Posts: 47 guyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to guyer
RE: Why won't this fopen() or file() work?

Why not use a db? You're making your life very difficult.

Reply With Quote
  #3  
Old August 29th, 2002, 06:05 PM
rxsid rxsid is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 86 rxsid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Why won't this fopen() or file() work?

I have thought about it, but was thinking that since there will be an enourmous amount of traffic with this script...I didn't wan't to have that many hits on my SINGLE instance of a database on the web server I'm on.

Reply With Quote
  #4  
Old August 29th, 2002, 06:14 PM
guyer guyer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN USA
Posts: 47 guyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to guyer
RE: Why won't this fopen() or file() work?

file() keeps the newline on the end of each array element. It seems to me that you have a pipe delimited file. Just do this:
Code:
$fp=fopen("TesingIN.txt","r+");
while ($line=fgetcsv($fp,1000,"|"){
  // DO STUFF
}
fclose($fp);

Reply With Quote
  #5  
Old August 29th, 2002, 06:28 PM
rxsid rxsid is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 86 rxsid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Why won't this fopen() or file() work?

Thanks guyer for the suggestion...I'll give it a whirl!

Reply With Quote
  #6  
Old August 30th, 2002, 09:15 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Why won't this fopen() or file() work?

there is a solution to db driven authentication system that doesn't access db on every page request. look at this nice phpbuilder article:

http://www.phpbuilder.com/columns/tim20000505.php3

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Why won't this fopen() or file() work?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway