Ok, here's my programming dilemma. I have a task manager on my website programmed in PHP. I want to write a script that will e-mail me my tasks for the day. I can set up a cron job for it that will run it at 12:05am or something. For security, I may put the script that is run by the cron job in a folder outside of my public website, but I'd prefer not to if possible.
Those are the specs, here's my problem. My task manager is private, so it forces you to log in by forwarding you to the login page if you're not logged in. The cron job isn't coming from a browser so it returns no cookie with a session id to show whether you're logged in or not, and it wouldn't be logged in with the cron job anyway. So, how do I detect when the PHP script is running standalone from a cron job so I can make it bypass the login? It's probably not a big deal, I'm just not sure how to do it (what environment variables I should check, etc.).
Ok, here's what I did. Some variables are not available from the command line, like I thought. The manual didn't recommend a specific variable to use, but it did say explicitly that "If PHP is running as a command-line processor, [$PHP_SELF] is not available", so I used $PHP_SELF. I also found out about using PHP from the command line.
If $PHP_SELF isn't defined, I turn off sessions and the web-based authentication, which I don't think is a security hole because no one but me (and root) can run my scripts from the command line. I also set $PHP_SELF to $argv[0] so that my forms will still work in the code generated from the command line, and I set a "base href" for my script so it'll still go to the right place when I click on links in the HTML e-mail.
The cron job runs a notify script which calls my main tasks script from the command line and e-mails the output. So now I get my tasks in the mail every morning. I'll never forget anything again! 
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):