Cron job access question
Moderator: General Moderators
Cron job access question
I have some files on my "online text based game" that i'm creating that are used in cron jobs. I was just wondering though is there something in PHP I can add at the top of these files or in them somewhere which stops people like me or anyone else from accessing them and getting it to run what is in the file?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
That would depend on how your cron job accesses the files. If you make a web request, .htaccess could block it. But if the request is a file system level one, .htaccess won't affect it.
is what I usually toss in. You could add an exception for localhost or the server's IP, but if you're on a shared host, that could be dangerous again.
http://httpd.apache.org/docs/1.3/howto/auth.html#access
Code: Select all
Order deny, allow
Deny from allhttp://httpd.apache.org/docs/1.3/howto/auth.html#access
My cron jobs are ran from the Cron Job section in cPanel (in Standard Mode)
Example:
I will look into link.
Example:
Code: Select all
/usr/bin/php -q /home/dalehay/public_html/PATH/TO/FILE- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Or you could add something like this to each file.
Code: Select all
$program_name = "myprogram.php"; // This is the name of this program file
if (basename($_SERVER['PHP_SELF']) == $program_name)
{
echo "You can not access this file directly!";
die();
}That's cleverAKA Panama Jack wrote:Or you could add something like this to each file.
Code: Select all
$program_name = "myprogram.php"; // This is the name of this program file if (basename($_SERVER['PHP_SELF']) == $program_name) { echo "You can not access this file directly!"; die(); }
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Actually for those that have Register Globals enabled this would be better...
Code: Select all
if (basename($_SERVER['PHP_SELF']) == "myprogram.php")
{
echo "You can not access this file directly!";
die();
}Anyways, I believe the easiest way to solve this problem would be to run this cron
As you can see, the cron script is not in the public_html directory. Therefore, its not accessable.
Code: Select all
/usr/bin/php -q /home/dalehay/cron.phpSet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.