Web Hosting Talk







View Full Version : Automatic Script Running


jung_ming2611
04-13-2006, 04:14 PM
Hi, I was wondering if anyone could help with a little problem of mine.

I currently have a website which I use the .htaccess file. This file gets modified quite alot but the changes are always constant.

What I would like is a little app that runs on the server that will either replace the entire content of an .htaccess file or one that will switch(by renaming?) the .htaccess file for me.

Does anyone know if this is possible?

thanks in advance.

drakazz
04-13-2006, 04:25 PM
Cron/Cron Jobs

Allows you to execute something periodically (e.g. each 5 minutes).
If you have cPanel, then it's easily done. If you have SSH access, you'll need to ask google about it.

jung_ming2611
04-13-2006, 06:12 PM
hi, thanks for your reply.

Im not sure that would work because when I do change the ..htaccess files, it is not a certain time period, but more when i need it.
Id like it so that I can simply run the file via the web and it will change or swap an .htaccess file.

xskter9000
04-13-2006, 06:17 PM
There are some features in PHP that could help. I can't remember off of the top of my head but if you program it right you can run the script and it will replace the files for you.

jung_ming2611
04-13-2006, 06:25 PM
hrmm... i shall try and look for this...

drakazz
04-14-2006, 02:09 AM
hi, thanks for your reply.

Im not sure that would work because when I do change the .htaccess files, it is not a certain time period, but more when i need it.
Id like it so that I can simply run the file via the web and it will change or swap an .htaccess file.
<?php
$mysecretpassword="password";
if ( $_SERVER['QUERY_STRING']==$mysecretpassword ) {
unlink(".htaccess");
/// Either This
copy(".htaccessnew",".htaccess");
echo "Done!";
// Or this:
// $f=fopen(".htaccess","r+");
// $data="RewriteEngine On\n....";
// fwrite($f,$data);
// fclose($f);
}
?>

:)
you just go to the file like this:
http://mydomain.com/updatehtaccess.php?password or to whatever password you set.

jung_ming2611
04-14-2006, 08:40 AM
you are a star! :)

I shall try this out later on today when i find some free time to waste.

thanks again.

edit: what would I do if I wanted to update 2 .htaccess files? both of which are in subfolders?

ie: I want to change the htaccess files in /folder1 and /folder2

could I just replace this:

unlink(".htaccess");
/// Either This
copy(".htaccessnew",".htaccess");

with this:

unlink("folder1/.htaccess");
copy("folder1/.htaccessnew1","folder1/.htaccess");
unlink("folder2/.htaccess");
copy("folder2/.htaccessnew2","folder2/.htaccess");
]
?

jung_ming2611
04-14-2006, 01:48 PM
just to let you know it worked and the modifications I guessed also worked.

thanks v. much :)

drakazz
04-14-2006, 03:10 PM
just to let you know it worked and the modifications I guessed also worked.

thanks v. much :)
Np, that's just the basics. If you need any help, visit FreeNode IRC ##php channel

arkin
04-14-2006, 05:05 PM
Not a real relevant question, but do you mind me asking the purpose of switching .htaccess files every now and then?

There may be a method where you can use the same one.

jung_ming2611
04-14-2006, 06:46 PM
the reason for switching htaccess is for ip address restriction.

basically, when i go to one place, I have it denied to a different ip so that the users at that place cant access it. but when i go to that place, I would like to unrestrict it until I leave.

What is your method for htaccess switching? Im intriegued now :)