Forum Moderators: coopster
I use simple two lines in .htaccess
php_value include_path
php_value auto_prepend_file
The script works fine.
I wanted to improve it by adding a few lines that would write some of the data into a flat file. The testing code is this:
$fp = fopen("log.txt", "a");
$test = "test";
fwrite($fp, $test);
fclose($fp);
I have CHMOD 777 on log.txt. If I run this as a separate PHP file, just by typing it into my browser’s address bar, it works fine. If I include it or put it straight into my PHP script that loads via .htaccess, nothing happens.
I wonder about difference between auto_prepend_file and regular run of any PHP file.
.htaccess is set to parse HTML as PHP and all of my pages are static HTML.
My test tells me the problem is not about code itself but how certain PHP functions work.
The bottom question is: can you write to a file straight from PHP script being setup in this way?
Thanks
php_value include_path ".:/path/to/includes"
php_value auto_prepend_file "/path/to/file.php"
Note the "." in the include path. This allow relative includes.
The directives you are setting in your .htaccess file are not correct.
The way how I have them works fine for all what the script does, except the new part that should write to a file.
Nevertheless, I did per your suggestion, and saw no change. Script still works fine, but my test part does not write into the file.
Finally, I run my script just as any page, from within the browser, and writing worked fine.
It is something about that PREPEND and writing to a file. But what? Some condition for that writing part is missing.
Then make sure you are using the correct directive for your server for evaluating htm, html, shtml, etc. as PHP files.
Otherwise the server will drop the php stuff that it is supose to auto-prepend.
goodluck...I tried your exact code and got it working for my server so it is very possible.
Here is my .htaccess code(work for php, html, and htm pages):
AddType application/x-httpd-php .html .htm
php_value auto_prepend_file test.php