PHP判断用户登录简单代码范例

一个PHP类,结合MYSQL,专用于判断登录用户名和密码是否正确,在类中可返回登录结果,正确则进入指定页,错误则弹出提示。将本代码保存为任意文件名的PHP后缀文件,用的时候include。

PHP判断用户登录简单代码范例

<?php
class checklogin
{
   var $name;
   var $pwd;
   function __construct($username,$password)
   {
     $this->name=$username;
     $this->pwd=$password;
   }
   function checkinput()
   {
     global $db;
     $sql="select * from tb_manager where name='$this->name' and pwd='$this->pwd'";
     $res=$db->query($sql);
     $info=$db->fetch_array($res); 
     if($info['name']==$this->name and $info['pwd']==$this->pwd)
     {
         $_SESSION[admin_name]=$info[name];
         $_SESSION[pwd]=$info[pwd];
         echo "<script>alert('登录成功!);window.location.href='index.php';</script>";
     }
     else
     {
         echo "<script language='javascript'>alert('登录失败!');history.back();</script>";
         exit;
     }
   }
}
?>

范例sql语句中的表的名字可以根据自己的数据库随意修改即可。

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...