Lodius2000 Posted February 7, 2009 Share Posted February 7, 2009 possibly wrong forum, mods feel free to move it I need to make a cron script that is not publicly accessable, it is for a game that needs to reset once a month. since it is a game, and the cron script would reset the game, placing it in www.example.com/cron.php would allow anyone who didnt like the way the game was going to reset it if they could find the cron script. I thought about putting it in www.example.com/directory/cron.php and then htaccessing 'directory' but I am not sure if you can pass htaccess info in your cronjob. I also thought about testing for a session identifyier within cron.php, before the cron part runs, but then I need to pass a session variable in my cronjob is it possible to send variables (hta or php) through cronjobs, if so how? or is there a better method? thanks Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/ Share on other sites More sharing options...
Prismatic Posted February 7, 2009 Share Posted February 7, 2009 possibly wrong forum, mods feel free to move it I need to make a cron script that is not publicly accessable, it is for a game that needs to reset once a month. since it is a game, and the cron script would reset the game, placing it in www.example.com/cron.php would allow anyone who didnt like the way the game was going to reset it if they could find the cron script. I thought about putting it in www.example.com/directory/cron.php and then htaccessing 'directory' but I am not sure if you can pass htaccess info in your cronjob. I also thought about testing for a session identifyier within cron.php, before the cron part runs, but then I need to pass a session variable in my cronjob is it possible to send variables (hta or php) through cronjobs, if so how? or is there a better method? thanks You can put it outside of the web root or require a key to activate the file cron.php?key=8sdfn3nDND9383nf83ampzgl something like that Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-756899 Share on other sites More sharing options...
Lodius2000 Posted February 7, 2009 Author Share Posted February 7, 2009 yeah I didnt even think about get vars solved Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-756918 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 doing it with a 'key' like that still gives users opportunity to gain access. Put it outside of your web root, problem solved. Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-756931 Share on other sites More sharing options...
Lodius2000 Posted February 12, 2009 Author Share Posted February 12, 2009 but then how do you access it through cron, because I thought a cron job directed the server's browser to a webpage Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-760182 Share on other sites More sharing options...
corbin Posted February 12, 2009 Share Posted February 12, 2009 Use the PHP CLI to call the script? /path/to/php /path/to/script.php Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-760191 Share on other sites More sharing options...
gizmola Posted February 12, 2009 Share Posted February 12, 2009 Just to summarize for you, cron, is a unix specific job scheduling system. It will run programs of any type on a particular schedule. Thus cron is a good solution for scheduling recurring jobs, like a monthly batch job. It is not a part of PHP, although php scripts can be set to run via cron. There are plenty of resources on how to set up cron. The primary way is to use crontab -e to edit the cron schedule. In the example of a script that is in webspace, cron can not call those scripts directly, because they are meant to be accessed by a web client using HTTP protocol. You can use wget or lynx or curl to accesss the scripts, but as they are usually not scripts that require webspace, the best alternative is to write the script in php and call it with the php command line interpreter. Make sure that you have this installed on your server, and that you can run it from a shell. You can test this running php -v. You should get output like this: [david@penny ~]$ php -v PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies Assuming that this works on your server, then you can use corbin's technique to call your php script from cron. That script can also be outside your web root, as stated by others. Quote Link to comment https://forums.phpfreaks.com/topic/144229-making-cron-not-publicly-accessable/#findComment-760263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.