.htgroup 文件示例:
admin: user2
editor: user1 user3
writer: user3
class Htgroup { private $file = ''; private function write($groups = array()) { $str = ''; foreach ($groups as $group => $users) { $users_str = ''; foreach ($users as $user) { if (!empty($users_str)) { $users_str .= ' '; } $users_str .= $user; } $str .= "$group: $users_str\n"; } file_put_contents($this -> file, $str); } private function read() { $groups = array(); $groups_str = file($this -> file, FILE_IGNORE_NEW_LINES); foreach ($groups_str as $group_str) { if (!empty($group_str)) { $group_str_array = explode(': ', $group_str); if (count($group_str_array) == 2) { $users_array = explode(' ', $group_str_array[1]); $groups[$group_str_array[0]] = $users_array; } } } return $groups; } public function __construct($file) { if (file_exists($file)) { $this -> file = $file; } else { die($file." doesn't exist."); return false; } } public function addUserToGroup($username = '', $group = '') { if (!empty($username) && !empty($group)) { $all = $this -> read(); if (isset($all[$group])) { if (!in_array($username, $all[$group])) { $all[$group][] = $username; } } else { $all[$group][] = $username; } $this -> write($all); } else { return false; } } public function deleteUserFromGroup($username = '', $group = '') { $all = $this -> read(); if (array_key_exists($group, $all)) { $user_index = array_search($username, $all[$group]); if ($user_index !== false) { unset($all[$group][$user_index]); if (count($all[$group]) == 0) { unset($all[$group]); } $this -> write($all); } } else { return false; } } }
$groupHandler = new Htgroup('/home/myuser/.htgroup'); // Add user 'user1' to group 'admin' in .htgroup. Group will be automatically created if it doesn't exist. $groupHandler -> addUserToGroup('user1', 'admin'); // Delete user 'user1' from group 'admin' in .htgroup. Group will be automatically removed if it doesn't contain any users. $groupHandler -> deleteUserFromGroup('user1', 'admin');
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前By尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
4 週前By尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前ByDDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前ByDDD

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver Mac版
視覺化網頁開發工具