Jump to content

making cron not publicly accessable


Lodius2000

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.