Just as a test, try doing this in place of fwrite:
Code:
$user=$_POST['user'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$data2="elseif(\$user==\"$user\" && \$pass==\"$pass\") {
session_start();
\$_SESSION['user']='$user';
\$_SESSION['pass']='$pass';
\$_SESSION['logged']='yes';
\$_SESSION['email']='$email';
else {";
$data=fopen("phpscripts/login.php","r+");
$data3=str_replace("else {", $data2, $data);
echo htmlentites($data3);
//fwrite($data, $data3);
fclose($data);
print("dfg");
If it outputs something like Resource_id #1, then it is an issue with the fopen command and you may need to choose a different mode or recode it to read the file, then rewrite the file.
Hope this helps.
Edit: Also, in your $data2 string, you are missing the part in red. You may want to add it so that the script will work after you get the writing to the file part worked out.