I am using ooowebhost. I have a PHP file, which I want that normal user should not be able to run it except cron job. As this file is inside public folder so it hard to protect from normal user but let cron job executor to access it.
Asked
Active
Viewed 67 times
-1
-
I want to secure one php file from normal user but let it to be accessible for corn job executor. – user8462556 Aug 21 '17 at 11:57
-
1You can probs achieve this with .htaccess please see https://stackoverflow.com/questions/11728976/how-to-deny-access-to-a-file-in-htaccess – IsThisJavascript Aug 21 '17 at 11:58
1 Answers
0
you can block your script executing from browser, but run through cron/cli.
Method 1: Add below line in the start of the script,
if (php_sapi_name() !='cli') exit;
OR
Method 2:
Add in the start of the script,
if ($_SERVER['HTTP_USER_AGENT'] != 'yourSecretAgent') exit;
replace agent ,
Thanks, M.AkberKhan

Muhammad Akber Khan
- 772
- 4
- 17