Page 1 of 1

I couldn't write in file

Posted: 2019/02/12 16:41:49
by xo)mora
Hi I have a conflict, I couldn't write from web the visit counter, the code is:

<?php
$handle = fopen("counter.txt", "r");
$fileip = file_get_contents("counter.txt");
if(!$handle){
echo "Archivo bloqueado";
}
else {
$counter=(int )fread($handle,20);
fclose($handle);
$counter++;
echo "<b><font face='arial' size='4' color='#C10434'>VISITAS: &nbsp;&nbsp;". $counter . " <br>" ;
$handle= fopen("counter.txt", "w" ) ;
fwrite($handle,$counter) ;
fclose ($handle) ;
}
?>

I found that probably the problem is Selinux Permissions: https://lists.centos.org/pipermail/cent ... 15653.html

Probably I will execute: chcon -R -t httpd_sys_rw_content_t /var/www/html BUT the web server has another applications like joomla and perl.


Please will you help to find the solution?

Thanks a lot.

Re: I couldn't write in file

Posted: 2019/02/12 16:43:58
by TrevorH
Move your file somewhere that selinux does allow the web server to write.

Re: I couldn't write in file

Posted: 2019/02/12 17:35:34
by xo)mora
Move your file somewhere that selinux does allow the web server to write.

Thanks a lot, I moved and the counter grew.