我需要在我的网站上创建一个最后登录成员的列表,但我不想使用 MySQL。我在stackoverflow和Google中进行了一些搜索并编写了以下代码:
////////////CHECK LIMIT
$storage = "engine/data/write.txt";
$readz = file_get_contents($storage);
$listz = explode('|||',$readz);
$counter = count( $listz );
if($counter > "3"){
$stop = "1";
}else{
$stop = "0";
}
if($stop == "0"){
///REMOVE MEMBER IF AVAILABLE
if ( preg_match("<!-- UserID: {$member_id} -->", $readz)){
$content = file_get_contents($storage);
$content = str_replace("<!-- UserID: {$member_id} -->".$user."|||", '', $content);
file_put_contents($storage, $content);
}
//ADD MEMBER AGAIN
if ( !preg_match("<!-- UserID: {$member_id} -->", $readz)){
$beonline_file = fopen($storage, "a+");
fwrite($beonline_file, "<!-- UserID: {$member_id} -->".$user."|||");
fclose($beonline_file);
}
}
问题是我不能设置限制!我如何编辑此代码以设置限制以在文本文件中仅添加20 个用户?