<html><body>
<?php

// Writing to files with r+ mode
/* Note the directory to write to must have public writing permissions */
/* Don't have public directories/files with public writing permissions */
/* Having a word writable directory/file is a security risk. */
/* You may write to a non-public file by changing the permissions 
 (to allow it to be writable) of the file in the program itself before 
 you start writing, and then changing them back in the program itself 
 to make it non writable
*/


$t1 = "XX XX,0,0";
$t2 = "ZZ ZZ,0,0";

// Try to open the file
@ $f = fopen('/home/abu-jeib/temp/a.txt','r+');

// If not opened successfully
if (!$f)
{
	echo "ERROR: file can't be opened.<P>\n";
	exit;
}
else // If succeeds
{
	// Read two lines from the file
	echo "The first two lines are: <br>\n";
	$s = fgets($f);
	echo "$s<br>\n";
	$s = fgets($f);
	echo "$s<br>\n";

	// Write two lines to the file
	fwrite($f,$t1."\n");
	fwrite($f,$t2."\n");

	// Close the file
	fclose($f);
}

?>
</body></html>
