Hi all:
I have a php script that I am running using s cron job. It contains the following include:
require($_SERVER['DOCUMENT_ROOT'].'/scr/scrSanitize.php');
This is not being recognized when running as a cron job. The following page is a good thread on this subject, but I cannot figure out how to get their answer to work for me. http://stackoverflow.com/questions/2100545/serverdocument-root-does-not-work-in-the-php-script-running-through-cron
So how does one recode require($_SERVER['DOCUMENT_ROOT'].'/scr/scrSanitize.php'); so it works on a cron job?
Thanks !
you need the full path starting at '/'.
If you are running the script via the command line (e.g. called from the cron job as something like "php path/to/file.php") then there is no web server involved, so $_SERVER variables won't exist (or at least won't be populated). Therefore you'll need to reference the required file via a relative or absolute file system path.
jeepin81;11002211 wrote:you need the full path starting at '/'.
Or a relative path, likely using "../", or "../../", etc., to get down to what would be the document root if it were being run as a web page.
wont the absolute root path start with '/'?
jeepin81;11002215 wrote:wont the absolute root path start with '/'?
Yes (unless it's on Windoze). But you do not have to use a full path to require/include a file. It all depends on what the complete story is here and how portable the script needs to be.
Thanks all! The following worked!
require('/home/myusername/public_html/scr/scrSanitize.php');