Page 1 of 1

Glob() Function.

Posted: Tue Feb 23, 2010 4:22 am
by HALDOR
Hello!

Please, ¿Does anyone know, how can I activate the glob() function from the php.ini on the server?

thank you very much, and sorry for my english, is terrible :)

Re: Glob() Function.

Posted: Sat Feb 19, 2011 11:44 pm
by amertad
help : http://seclists.org/fulldisclosure/2005/Sep/1


new cache.php

Code: Select all

<?php
////////////////////////////////////////////
// Opencart.com
// Farhad Sakhaei ~ parsmizban.com
// Mohammad Reza Mahmoudi ~ iropencart.com
///////////////////////////////////////////

	 function MRMs_glob($dir){
	  $files = array();
	   if(is_dir($dir)){
		   if($dh=opendir($dir)){
		   while(($file = readdir($dh)) !== false){
		      	$files[]=$dir.$file;
				}}
			}
		return $files;
		}
		
/////////////////////////////////////////

final class Cache { 
	private $expire = 3600; 

  	public function __construct() {
		$files = MRMs_glob(DIR_CACHE . 'cache.*');
		
		if ($files) {
			foreach ($files as $file) {
				$time = substr(strrchr($file, '.'), 1);

      			if ($time < time()) {
					if (file_exists($file)) {
						@unlink($file);
					}
      			}
    		}
		}
  	}

	public function get($key) {
		$files = MRMs_glob(DIR_CACHE . 'cache.' . $key . '.*');
		
		if ($files) {
    		foreach ($files as $file) {
      			$cache = '';
				
				$handle = fopen($file, 'r');
      			
				if ($handle) {
					$cache = fread($handle, filesize($file));
	  
					fclose($handle);
				}

	      		return unserialize($cache);
   		 	}
		}
  	}

  	public function set($key, $value) {
    	$this->delete($key);
		
		$file = DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->expire);
    	
		$handle = fopen($file, 'w');

    	fwrite($handle, serialize($value));
		
    	fclose($handle);
  	}
	
  	public function delete($key) {
		$files = MRMs_glob(DIR_CACHE . 'cache.' . $key . '.*');
		
		if ($files) {
    		foreach ($files as $file) {
      			if (file_exists($file)) {
					@unlink($file);
					clearstatcache();
				}
    		}
		}
  	}
}
?>