|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
RE: Why won't this fopen() or file() work?
Why not use a db? You're making your life very difficult.
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
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);
|
|
#5
|
|||
|
|||
|
RE: Why won't this fopen() or file() work?
Thanks guyer for the suggestion...I'll give it a whirl!
|
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Why won't this fopen() or file() work? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|