函数总结
时间:2006-03-28 来源:freespray
一,记录用户登录信息:
function recordip($name){ $fp=fopen("record/ip.txt","a+");
fseek($fp,0,SEEK_END);
$nowtime=date(YÄêmÔÂjÈÕ);
$ip=getenv("REMOTE_ADDR");
$str="用户名".$name;
$str=$str."IP:".$ip;
$str=$str."登录时间:".$nowtime;
$str=$str."登录论坛成功";
$write=fwrite($fp,$str);
fclose($fp);
}
二,读取用户登录信息
function seeinfo()
{
$filename="record/ip.txt";
$fd=fopen($filename,"r");
$string=fread($fd,filesize($filename));
fclose($fd);
$string=str_replace("\n","
",$string);
$string=str_replace("\'","",$string);
echo $string;
}
三,登录,注册验证
注册处理:
function check($name,$pwd){ //登录验证
$sql="select * from users where uname='$name'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($answer=mysql_fetch_array($result))
{
if($pwd==$answer['pwd'])
{
$_SESSION['username']=$name;
updatestatus($name);
$lasttime=date("Y-n-j h:i:s");
echo "alert('登录成功');";
echo "this.location.href='bbs.php';";
}
else
{
echo "alert('密码有误');";
echo "this.location.href='login.php';";
}
}
else
{
echo "你尚未注册,请注册后再登录";
}
}
function flag(){ //判断登录
if(!isset($_SESSION['username']) && $_SESSION['username']==""){
echo "你尚未登录,不能查看此页";
exit;
}
}
function checkreg($uid,$pwd,$pwd1,$email){ //注册
if($uid==""){
echo "用户名不能为空";
exit;
}
if($pwd==""){
echo "密码不能为空";
exit;
}
if($pwd1!=$pwd){
echo "两次密码不一致";
exit;
}
if(strstr($uid,"@")){
echo "不正确的邮箱格式";
exit;
}
$sql="select * from users where uname='$uid'";
print_r($sql);
$result=mysql_query($sql);
$nums=mysql_num_rows($result);
echo $nums;
$uid=htmlspecialchars($uid);
$pwd=md5($pwd);
$lasttime=date("Y-n-j h:i:s");
echo $lasttime;
if(empty($nums)){
$sql="insert into users(uname,pwd,email) values('$uid','$pwd','$email')";
print_r($sql);
$result=mysql_query($sql);
if($result){
$_SESSION['username']=$uid;
echo $uid;
updatestatus($uid);
echo "alert('注册成功');";
echo "this.location.href='bbs.php';";
}
else
{
echo "alert('注册失败');";
echo "javascript:history.go(-1)";
}
}
else
{
echo "此用户名已存在,请用其它的用户名注册";
}
}
function updatestatus($name){
//更新登录状态
$lasttime=date("Y-n-j h:i:s");
$ip=getenv("REMOTE_ADDR");
$sql="update users set status=status+1 where uname='$name'";
print_r($sql);
$result=mysql_query($sql);
$sql="select * from useronline where uname='$name'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
$now=date("Y-n-j h:i:s");
$diff=strtotime($now) - strtotime($last);
echo $diff;
$sql="update useronline set logintime='$nowtime' where uname='$name'";
print_r($sql);
$result=mysql_query($sql);
}
else
{
$sql="insert into useronline(uname,logintime,ip) values('$name','$lasttime','$ip') ";
$result=mysql_query($sql);
}
}
function recordip($name){ $fp=fopen("record/ip.txt","a+");
fseek($fp,0,SEEK_END);
$nowtime=date(YÄêmÔÂjÈÕ);
$ip=getenv("REMOTE_ADDR");
$str="用户名".$name;
$str=$str."IP:".$ip;
$str=$str."登录时间:".$nowtime;
$str=$str."登录论坛成功";
$write=fwrite($fp,$str);
fclose($fp);
}
二,读取用户登录信息
function seeinfo()
{
$filename="record/ip.txt";
$fd=fopen($filename,"r");
$string=fread($fd,filesize($filename));
fclose($fd);
$string=str_replace("\n","
",$string);
$string=str_replace("\'","",$string);
echo $string;
}
三,登录,注册验证
注册处理:
function check($name,$pwd){ //登录验证
$sql="select * from users where uname='$name'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($answer=mysql_fetch_array($result))
{
if($pwd==$answer['pwd'])
{
$_SESSION['username']=$name;
updatestatus($name);
$lasttime=date("Y-n-j h:i:s");
echo "alert('登录成功');";
echo "this.location.href='bbs.php';";
}
else
{
echo "alert('密码有误');";
echo "this.location.href='login.php';";
}
}
else
{
echo "你尚未注册,请注册后再登录";
}
}
function flag(){ //判断登录
if(!isset($_SESSION['username']) && $_SESSION['username']==""){
echo "你尚未登录,不能查看此页";
exit;
}
}
function checkreg($uid,$pwd,$pwd1,$email){ //注册
if($uid==""){
echo "用户名不能为空";
exit;
}
if($pwd==""){
echo "密码不能为空";
exit;
}
if($pwd1!=$pwd){
echo "两次密码不一致";
exit;
}
if(strstr($uid,"@")){
echo "不正确的邮箱格式";
exit;
}
$sql="select * from users where uname='$uid'";
print_r($sql);
$result=mysql_query($sql);
$nums=mysql_num_rows($result);
echo $nums;
$uid=htmlspecialchars($uid);
$pwd=md5($pwd);
$lasttime=date("Y-n-j h:i:s");
echo $lasttime;
if(empty($nums)){
$sql="insert into users(uname,pwd,email) values('$uid','$pwd','$email')";
print_r($sql);
$result=mysql_query($sql);
if($result){
$_SESSION['username']=$uid;
echo $uid;
updatestatus($uid);
echo "alert('注册成功');";
echo "this.location.href='bbs.php';";
}
else
{
echo "alert('注册失败');";
echo "javascript:history.go(-1)";
}
}
else
{
echo "此用户名已存在,请用其它的用户名注册";
}
}
function updatestatus($name){
//更新登录状态
$lasttime=date("Y-n-j h:i:s");
$ip=getenv("REMOTE_ADDR");
$sql="update users set status=status+1 where uname='$name'";
print_r($sql);
$result=mysql_query($sql);
$sql="select * from useronline where uname='$name'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
$now=date("Y-n-j h:i:s");
$diff=strtotime($now) - strtotime($last);
echo $diff;
$sql="update useronline set logintime='$nowtime' where uname='$name'";
print_r($sql);
$result=mysql_query($sql);
}
else
{
$sql="insert into useronline(uname,logintime,ip) values('$name','$lasttime','$ip') ";
$result=mysql_query($sql);
}
}
相关阅读 更多 +