If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Page accessibilty?

I'm not sure if this is in the correct place or not (apologies if this is the case), but here goes anyway.

I have a cron job set up to visit mypage.php every hour. How would I go about making this page accessible ONLY to cron? My reason is that I don't want any Tom, **** or Harry visiting the page and triggering the script inside it (which would totally mess up a lot of things).

I'm not sure if this can be done with something like chmod or if I would need a special script (PHP or otherwise).

There are a number of ways you can do this. The most secure (at least without lots of additional setup) is what John said above.

Here are some other ideas if that is not available:
1. Limit access by IP-- it should only be the local IP (I'm not sure what this value is for a cron job and it would be hard to test, but you could figure it out with enough trial and error).
2. Add a variable in the script to check if the access is legitimate. You could do this with a variable in the url: ?cron=1. Then use $_GET['cron'] and be sure it's equal to 1... anyone who doesn't know to use that in the url will be denied access. That's not "secure", but it is secure enough if no one knows the trick-- you can think of is as an unknown method few people would guess about, but also as a username/password combo with "cron" as the username and "1" as the password-- feel free to change them to anything you want (though be aware that particularly odd symbols in the url might not work).
3. Don't worry about it-- just don't tell anyone the address for the page. Assuming no other sources link to it, give the page a weird name and no one will go to it.
4. Why can't others go to it? Aside from server load, if you don't output anything (and you wouldn't-- cron jobs don't have output html, etc.), then they won't know what they're seeing-- just copy a 404 error and output that while actually executing the code. They'll have no idea what they're seeing, see no behind the scenes info, and the process will be run extra-- just an extra run for the "cron" job.
5. You could also try something with .htaccess... not sure how you'd monitor the traffic, though.
6. Finally, if security is a huge issue, you could do something beyond php cron jobs-- do something on the server that is not accessible via the web, like an exe that does the cron stuff. This is more work, but it's also more secure if there is really something crucial about this page.

I'm sure there are many other ways to do this, but those should be plenty for now. You could also combine a few.