2

I have a website which I run a PHP script for updating its Database. What is considered to be an acceptable location on the server to store such scripts? Obviously only the root (running a cronjob to start the script) should have access to it.

Thanks,

Joel

1

If you are worried about access to this script you can add a random string to the command line argument of the cron job string e.g.

php /path/to/script.php random_string

Then in your script.php you check argv0 to see if that string is exists and is correct before running the rest of your code.

Another way is to put the cron script in a folder and restrict its access using a .htaccess file. Here is an answer on how to do this: https://serverfault.com/questions/92192/apache-htaccess-file-to-restrict-access-to-all-files-unless-local-ip

  • 4
    Why not just put the script outside of your web root directory? – Lèse majesté Nov 18 '10 at 11:45
  • Yes that is a very valid point! – mar10 Nov 18 '10 at 12:12
  • Actually I was aiming to that point. I was wondering if there is a directory outside of the web root directory, that it is common to put scripts within. – Joel Nov 18 '10 at 12:32
  • @Joel: AFAIK, there is no common directory that such scripts are put in. I normally group these types of scripts with the application that it belongs to, so it just depends on their directory structure. As long as it's outside of your web root and inside your home directory (for shared hosting), then it's equally safe wherever you put it. – Lèse majesté Nov 18 '10 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.