How to change contents of . htaccess via php?

Asked

Viewed 129 times

0

I was wondering 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 certain 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, I would have this possibility via php?

  • file_get_contents() to read the file, file_put_contents() to write in the archive

  • Yes, but how could you use these commands to remove this line from the Deny command? With file_put_contents() I put content in the file, but to remove?

  • is just a hint where you can start. Hands the dough and good luck!

  • Hehe, I’ll try, but if you can’t, I’ll come back here

1 answer

0

You can try this one, just by swapping the "127.0." for the whole IP or the part.

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

<?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";
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.