I created a chat script which uses a flat file text database, the problem is when the chat logs are saved into the txt file the information is added to the top of the file and i would likeit to be added to the bottom.
How can this be done?
This is the code, what do i need to change?
PHP Code:
$user = $username ;
$f = file ( $file ) ;
$users = array( $user ) ;
header ( "Content-Type: text/html; charset=utf-8" ) ;
$fp = fopen ( $file , "w" ) ;
if (! $fp ) { die ( 'Can not write to file .' ) ; }
for ( $i = 0 ; isset( $f [ $i ])|| $i == 0 ; $i ++)
{
$e = explode ( '||' , $f [ $i ]) ;
if ( $e [ 2 ]== "\r\n" && ! in_array ( $e [ 0 ], $users ) && ( time () - $e [ 1 ] < $refresh * 2 ) ) $users []= $e [ 0 ] ;
if ( $i == 0 ) { fputs ( $fp , $user . "||" . time (). "||\r\n" ) ;
if ( isset( $HTTP_POST_VARS [ 'msg' ]) ) fputs ( $fp , $user . "||" . time (). "||" . str_replace ( "||" , "" , str_replace ( "\n" , "" , htmlspecialchars ( stripslashes ( $HTTP_POST_VARS [ 'msg' ])))). "\r\n" ) ; }
if ( ( $e [ 0 ]!= $user && $e [ 2 ]== "\r\n" ) || ( $i < $max && ( $e [ 1 ]+ $remain )> time () && $e [ 2 ]!= "\r\n" ) ) fputs ( $fp , $f [ $i ]) ;
}
fclose ( $fp ) ;
if (isset( $HTTP_GET_VARS [ 'f1' ]))
{
$f2 = file ( $file ) ;