How to change .htaccess content via php?

0

I wanted to know if there is any way to change .htaccess via php.

An example of what I want is that by htaccess I can restrict the access of a given ip with the command:

deny from 67.114.135.60

If I wanted to "unlock" user access via php (in an administrative area for example), without having to tinker with the file itself, would I have this possibility via php?     

asked by anonymous 16.03.2016 / 15:22

1 answer

0

You can try this, only by changing the "127.0." by the entire IP or by part.

Remember that if you put part of the ip, it will block all ip that starts with the number you set

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$deny_ip="127.0.";
if($ip==$deny_ip){
echo "acesso negado";
exit;
}
if(sizeof(explode($deny_ip,$ip))!=1){
echo "acesso negado";
exit;
}

echo "acesso permitido";
?>
    
16.03.2016 / 15:29