一段訪客代碼,也可以用於加鎖的操作

function counter() {
		$dir  = 'errorLog';
		$file = 'counter.log';
		 
		// 新建文件夾
		if (! file_exists($dir)) {
			mkdir($dir, 0777);
		}
		if (!is_readable($dir) || !is_writable($dir)) {
			chmod($dir, 0777);
		}
		 
		if (! file_exists($dir.'/'.$file)) {
			$handle = fopen($dir.'/'.$file, 'w');
			$num = 1;
			fputs($handle, $num);
			fclose($handle);
		} else {
			$num = intval(file_get_contents($dir.'/'.$file));
			++$num;
			file_put_contents($dir.'/'.$file, $num);
		}
		return $num;
	}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章