Jump to content

Editing .htaccess Online? [Code Needed]


Hard Powered

Recommended Posts

Hello,

 

I already have a banning script, however it's not particularly useful. It's alright but it's a lot of hassle downloading the .htaccess, editing it then having to upload it again. Also, if I don't want to give someone permission to access all my files then they cannot edit it. What I want is an online webpage on my website, this would of course be password protected. This page would open up the .htaccess file so we can edit it online and save it.

 

Does anyone know of an easy way to do this? This would be very helpful.

 

Thanks very much.

Link to comment
https://forums.phpfreaks.com/topic/103022-editing-htaccess-online-code-needed/
Share on other sites

Take a look at php file handling functions, like fopen(), fread() and fwrite(). There are lots of examples on php.net to accomplish what u want. The general idea is u read the file contents of htaccess and throw them in an input area, which after submitting writes its content to the htaccess.

Ok i threw some code to better explain u the procedure:

 

<?php
$handle = fopen('.htaccess', 'r');
$contents = fread($handle, filesize('.htaccess'));
if(isset($_POST['edit'])){
     $handle = fopen('.htaccess', 'w+'); //open the file for writing and truncate the length to zero
     $contents = $_POST['edit'];
     fwrite($handle, $contents); //write the contents to the file
}
?>
<form name="form1" method="post" action="">
  <textarea name="edit"><?php echo $contents; ?></textarea>
  <input type="submit" name="Submit" value="Submit" />
</form>

This makes me think of a question i have had for a bit.. kinda on the same subject as it deals with .htaccess and all..

 

I have a small server that I'm going to use as a live server eventually and I have friends and friends of friends who have in the past wanted me to host something for them now and again.. some of them just wanting a quick subdomain style option.. some wanting to use there own domain.. is it possible to edit the apache_conf or htacess file to work where it will accept a virtual domain container.. I'm lazy all I want to do in time is type in the domain via PHP if possible have it do all the edits via the script and then restart the server.. or not restart it if possible not wanting to restart the server im going to assume that its htaccess i would need to mess with. Hopeful someone understands what I wanna do.. an can answer..

 

by the way sorry to divert your orginal question.. Hard Powered

 

However I can think of an alternative.. worked for me a few times in the past..

 

With the use of PHP you could device your own banning script and require it with key pages on your site.. so where if the person is banned they will automaticly get redirected from the main pages and always sent to a "Banned" page..

 

Example if everything is ran through index.php

I would in the index.php

 

require ban.php

 

In ban.php I would do 2 things one, set a very unique $var that index.php would have to look for and if it wasn't set would exit the load of the page.. So this way it would be a bit harder to pull off loading the page without the ban.php as it would need to set that var.. then in the ban.php I would put my bans be it by user or by ip or whatever I usually use a database to store them and call them out via that script to use as an array if this person is banned then redirect them if not then let them pass... it may be a bit crude but has worked for me in the past fiarly well..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.