I have created a php page having some code, it has been set to run once a day through cpanel cron job feature.How can i prevent this page from direct run through the browser? Is there any feature in cpanel or i have to write some code in php? Thank you
Make your file ip specific.. ... IF(Your Server IP == '1212121212') -- execute your file ELSE --- no action.
Restrict outside access by IP address. OR restrict by adding some random query string. if($_GET['s'] != "F7X5TAS3CB42A53BQY4RCUTMZM45E7C2P69TP6J475B2ZYURN3VMAU897CKZ") { die('You are not authorized'); } // Execute your code here. Code (markup): use cron file as wget http://domain.com/cron.php?s=F7X5TAS3CB42A53BQY4RCUTMZM45E7C2P69TP6J475B2ZYURN3VMAU897CKZ
Put the file outside the web root - browsers can't access above the root, but cron can access anything on the computer. Or you could add the file to .htaccess and deny all. Since cron jobs don't run in the web server, .htaccess doesn't affect them.
Rukbat's solution is the best, create a directory outside of your web root for the cron job scripts, in that way any of these files can't be executed by using a browser..