I have tried this:
<?php
$data = $_POST['var'];
echo $data;//works fine
file_put_contents ('file1.txt', $data ) ;//file empty
file_put_contents('file2.txt', 'some output');//works fine
?>
And even this:
<?php
$data = $POST['var'];
$data = "some text".$data;
echo $data;//works fine
file_put_contents ('file1.txt', $data ) ;
//file only contains 'some text', $POST['var'] string seems to get stripped first
file_put_contents('file2.txt', 'some output');//works fine
?>
It almost seems as if file_put_contents() is rerunning the entire php block in a separate session where it does not have access to the $_POST array.