I have a script that I run manually through the browser on the first of each month, just after midnight. I don't think it matters, but I use this script to process credit cards.
I'd like to change that to run via cron, and then make it so that it can ONLY run via cron (ie, if I try to run it through the browser it will throw an error). I'm running Linux and WHM/cPanel.
What's the best way to do this? I considered adding this to the PHP script:
if (php_sapi_name() !== 'cli') {
header("Location: https://www.example.com/404.php");
exit;
}
but haven't tested it so I'm not sure if that works. It would give me the option of giving myself a password-encrypted backdoor, though, so I could run it via browser if necessary; something like:
if (php_sapi_name() !== 'cli' && $_GET['backdoor'] !== 'foo') {
header("Location: https://www.example.com/404.php");
exit;
}
I think that an easier option might be to just upload the script to a directory that's not accessible via browser (like /run/script.php), but I haven't tested it either so I don't know for sure that I'll be allowed to access MySQL and mail() that way.
Any thoughts or suggestions?