ApplicationVar.php 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class ApplicationVar
  3. {
  4. var $save_file;
  5. var $application = null;
  6. var $app_data = '';
  7. var $__writed = false;
  8. function __construct()
  9. {
  10. $this->save_file = __DIR__.'/httpdns.conf' ;
  11. $this->application = array();
  12. }
  13. public function setValue($var_name,$var_value)
  14. {
  15. if (!is_string($var_name) || empty($var_name))
  16. return false;
  17. $this->application[$var_name] = $var_value;
  18. }
  19. public function write(){
  20. $this->app_data = @serialize($this->application);
  21. $this->__writeToFile();
  22. }
  23. public function getValue()
  24. {
  25. if (!is_file($this->save_file))
  26. $this->__writeToFile();
  27. return @unserialize(@file_get_contents($this->save_file));
  28. }
  29. function __writeToFile()
  30. {
  31. $fp = @fopen($this->save_file,"w");
  32. if(flock($fp , LOCK_EX | LOCK_NB)){
  33. @fwrite($fp,$this->app_data);
  34. flock($fp , LOCK_UN);
  35. }
  36. @fclose($fp);
  37. }
  38. }
  39. ?>