用户写入到(.txt)文件里
php代码
/* 检查用户昵称是否重复 * 参数$user是登录用户的昵称 * 返回值为true时,昵称可用 * 返回值为false时,昵称不可用 */ function chklogin($file,$user){ $boo = false; if(file_exists($file)){ $userarr = file($file); /* 判断昵称是否重复 */ foreach($userarr as $value){ $tmparr = explode('#',$value); if($user == $tmparr[0]){ $boo = true; break; } } } return $boo; } /* 将登录的用户昵称写入到文件中 * 保存格式为:昵称#ip#登录时间 * $file:保存文件地址 * $user:昵称 * $ip:登录IP * $sex:性别 */ function addlogin($file,$user,$ip,$sex){ $tmp = $user.'#'.$ip.'#'.$sex.chr(13).chr(10); $fp = fopen($file,'a'); $boo = fwrite($fp,$tmp); fclose($fp); return $boo; } /* 将用户列表转为数组 * $file:用户列表文件 */ function storeuser($file){ $tmparr = file($file); $userarr = array(); foreach($tmparr as $value){ $tmparr = explode('#',$value); $userarr[] = $tmparr[0].','.$tmparr[2]; } return $userarr; } /* 将发言内容写入到文件中 * $file:保存文件地址 * $mess:保存内容 */ function addmess($file,$mess){ $fp = fopen($file,'a'); $boo = fwrite($fp,$mess.chr(13).chr(10)); fclose($fp); return boo; } /* 在文件中删掉用户 * $file:保存文件地址 * $user:要删除的用户 */ function deluser($file,$user){ $tmparr = file($file); $rearr = array(); foreach($tmparr as $value){ $tmp = explode('#',$value); if($tmp[0] != $user){ $rearr[] = $value; } } $fp = fopen($file,'w+'); foreach($rearr as $value){ fwrite($fp,$value); } fclose($fp); }
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Saving in R.E.P.O. Explained (And Save Files)
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1386
52

