第一次接触这种 查了好久也不会 =

WBOY
Lepaskan: 2016-06-23 13:42:50
asal
890 orang telah melayarinya

<?phpsession_start(); class chkuserlogin{     private $username;	private $password;        	public function __construct($username,$password){	   $this->username=$username;	   $this->password=$password;	   		  	   require_once("connn.php");	   $sql=mysql_query("select account from root where username='".$this->username."' and password='".$this->password."'",$conn);       $info=mysql_fetch_array($sql);	   if($info==false){	     echo "<script>alert('用户名或密码输入错误!');history.back();</script>";	     exit;	   }else{	     if($_SESSION["unc"]!=""){		   session_unregister("unc");		 } 		 session_register("unc");		 $_SESSION["unc"]=$this->username; 		 mysql_query("update root set logintimes=logintimes+1,lastlogintime='".date("Y-m-d H:i:s")."'",$conn);	     echo "<script>alert('登录成功!');window.location.href='login.php';</script>"; 	    }	  } }  $obj=new chkuserlogin($_POST["username"],md5($_POST["password"]));  $obj->chk();?>
Salin selepas log masuk


登录验证的一小段代码 我数据库为 localhost root 无密码 , 我数据库已保存了一组密码。 无限密码错误 跳转页面 而且也报错



= - 求解脱 拜谢


回复讨论(解决方案)

$sql=mysql_query("select account from root where username='".$this->username."' and `password`='".$this->password."'",$conn);//17行password外面加``,与mysql函数冲突
Salin selepas log masuk

请两个错误是在这句出现的
$obj=new chkuserlogin($_POST["username"],md5($_POST["password"]));

你可能不是在 post 方式下执行的程序
也可能提交过来的名字不对

var_dump($_POST);

= - 各位大神 我还是不知道怎么改 新手没学几天

你是怎么执行这个程序的

<!DOCTYPE html><html lang="en">  <head>    <meta charset="utf-8" />    <title>Administrator</title>                   <link href="./css/bootstrap.min.css" rel="stylesheet" />    <link href="./css/bootstrap-responsive.min.css" rel="stylesheet" />            <link href="./css/font-awesome.css" rel="stylesheet" />        <link href="./css/adminia.css" rel="stylesheet" />     <link href="./css/adminia-responsive.css" rel="stylesheet" />         <link href="./css/pages/login.css" rel="stylesheet" />     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><form name="connForm" method="post" action="conn.php" onSubmit="return InputCheck(this)">  <body>	<div class="navbar navbar-fixed-top">		<div class="navbar-inner">				<div class="container">						<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> 				<span class="icon-bar"></span> 				<span class="icon-bar"></span> 				<span class="icon-bar"></span> 							</a>						<a class="brand" href="./"> Admin</a>						<div class="nav-collapse">										</div> <!-- /nav-collapse -->					</div> <!-- /container -->			</div> <!-- /navbar-inner -->	</div> <!-- /navbar --><div id="login-container">			<div id="login-header">				<h3>欢迎登陆用户保用注册后台</h3>			</div> <!-- /login-header -->		<div id="login-content" class="clearfix">		 				<fieldset>					<div class="control-group">						<label class="control-label" for="username">用户名:</label>						<div class="controls">							<input type="text" class="" id="username" />						</div>					</div>					<div class="control-group">						<label class="control-label" for="password">密码:</label>						<div class="controls">							<input type="password" class="" id="password" />						</div>					</div>				</fieldset>								<div id="remember-me" class="pull-left">					<input type="checkbox" name="remember" id="remember" />					<label id="remember-label" for="remember">Remember Me</label>				</div>								<div class="pull-right">					<button type="submit" class="btn btn-warning btn-large">						Login					</button>				</div>			</form>					</div> <!-- /login-content -->							</div> <!-- /login-wrapper -->    <!-- Le javascript================================================== --><!-- Placed at the end of the document so the pages load faster --><script src="./js/jquery-1.7.2.min.js"></script><script src="./js/bootstrap.js"></script>  </body></html> = - 用这个 页面
Salin selepas log masuk
Salin selepas log masuk

<?phperror_reporting(0);$mysql_servername = "localhost"; //主机地址$mysql_username = "root"; //数据库用户名$mysql_password =""; //数据库密码$mysql_database ="root"; //数据库mysql_connect($mysql_servername , $mysql_username , $mysql_password);mysql_select_db($mysql_database); $username=$_POST['username'];$passowrd=$_POST['password'];if ($username && $passowrd){ $sql = "SELECT * FROM account WHERE username = '$username' and password='$passowrd'"; $res = mysql_query($sql); $rows=mysql_num_rows($res);  if($rows){   header("refresh:0;url=login.php");//跳转页面,注意路径   exit; } echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";}else { echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";}?>
Salin selepas log masuk

我重新写了这个代码 不用那个链接的 这个没报错了 但是无限用户名 密码不能为空 不管怎么输入

<!DOCTYPE html><html lang="en">  <head>    <meta charset="utf-8" />    <title>Administrator</title>                   <link href="./css/bootstrap.min.css" rel="stylesheet" />    <link href="./css/bootstrap-responsive.min.css" rel="stylesheet" />            <link href="./css/font-awesome.css" rel="stylesheet" />        <link href="./css/adminia.css" rel="stylesheet" />     <link href="./css/adminia-responsive.css" rel="stylesheet" />         <link href="./css/pages/login.css" rel="stylesheet" />     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><form name="connForm" method="post" action="conn.php" onSubmit="return InputCheck(this)">  <body>	<div class="navbar navbar-fixed-top">		<div class="navbar-inner">				<div class="container">						<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> 				<span class="icon-bar"></span> 				<span class="icon-bar"></span> 				<span class="icon-bar"></span> 							</a>						<a class="brand" href="./"> Admin</a>						<div class="nav-collapse">										</div> <!-- /nav-collapse -->					</div> <!-- /container -->			</div> <!-- /navbar-inner -->	</div> <!-- /navbar --><div id="login-container">			<div id="login-header">				<h3>欢迎登陆用户保用注册后台</h3>			</div> <!-- /login-header -->		<div id="login-content" class="clearfix">		 				<fieldset>					<div class="control-group">						<label class="control-label" for="username">用户名:</label>						<div class="controls">							<input type="text" class="" id="username" />						</div>					</div>					<div class="control-group">						<label class="control-label" for="password">密码:</label>						<div class="controls">							<input type="password" class="" id="password" />						</div>					</div>				</fieldset>								<div id="remember-me" class="pull-left">					<input type="checkbox" name="remember" id="remember" />					<label id="remember-label" for="remember">Remember Me</label>				</div>								<div class="pull-right">					<button type="submit" class="btn btn-warning btn-large">						Login					</button>				</div>			</form>					</div> <!-- /login-content -->							</div> <!-- /login-wrapper -->    <!-- Le javascript================================================== --><!-- Placed at the end of the document so the pages load faster --><script src="./js/jquery-1.7.2.min.js"></script><script src="./js/bootstrap.js"></script>  </body></html> = - 用这个 页面
Salin selepas log masuk
Salin selepas log masuk

你的用户名和密码没有提交过去啦 

红色框框分别加上
 name="username"
name="password"
再试试

 非常感谢 各位的帮助 让我在这条路上不至于不知道如何继续  问题已解决

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan