topical media & game development

talk show tell print

professional-php-11-logmessage.php / php



  <?php
  
  function logMessage(message) {
    LOGDIR = '/www/mysite/logs/';  //chmod 744 and chown nobody
    logFile = LOGDIR . 'mysite.log';
    hFile = fopen(logFile, 'a+'); //open for appending, create
                                    //the file if it doesn't exist
    if(! is_resource(hFile)) {
      printf("Unable to open \%s for writing.  Check file permissions.", logFile);
      return false;
    }
  
    fwrite(hFile, message);
    fclose(hFile);
  
    return true;
  }
  
  logMessage("Hello, log!\n");
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.