I encountered a problem that's been driving me nuts because it was generating a 500 error on the Apache server, and when that happened I couldn't see any of my debugging code. I finally found a way around the problem, but I still don't understand why my initial approach didn't work, and I'd like to understand.
My script used this command to open the file:
Code: Select all
$fp = fopen( $filename, 'r+' );If the script does not find the username, then it's a new customer creating a record for the first time. I used this function to identify when I'd come to the EOF:
Code: Select all
feof( $fp );Code: Select all
fseek( $fp, -1 * $len, SEEK_CUR ); // back up one record
if ( fwrite( $fp, "$user_to_match:$encrypted_password\n" ) === FALSE )
DataError( "Could not write to password file.\r\n" );
if ( !fclose( $fp ) )
DataError( "Could not close password file after writing.\r\n" );Finally I changed it to this, and this works:
Code: Select all
if ( !fclose( $fp ) )
DataError( "Could not close password file after writing.\r\n" );
$fp = fopen( $filename, 'a' ); // Open for appending, pointer at end of file.
if ( !$fp )
DataError( "Could not open password file for appending.\r\n" );
if ( fwrite( $fp, "$user_to_match:$encrypted_password\n" ) === FALSE )
DataError( "Could not write to password file.\r\n" );
if ( !fclose( $fp ) )
DataError( "Could not close password file after writing.\r\n" );