求写个比较简单的php登陆页面代码

麻烦分开写index.php login.php 以及sql文件和其他需要的各种部件SQL很简单的有一条记录就行(就是能用里面主要是看实例来学怎么添加 还望不吝赐教啊

index.php 录入页代码<form id="form1" name="form1" method="post" action="login.php">
<table width="400" border="0" align="center" cellpadding="1" cellspacing="1" class="tableborder">
<tr>
<td><div align="right">用户名:</div></td>
<td width="244">
<input type="text" name="User_name" id="User_name" /> </td>
</tr>
<tr>
<td><div align="right">密 码:</div></td>
<td><input type="Password" name="User_Password" id="User_Password" /></td>
</tr>
<tr>
<td>
<div align="right">
<input type="submit" name="button" id="button" value="提交" />
</div></td>
<td><input type="reset" name="button2" id="button2" value="重置" /></td>
</tr>
</table>
</form> login.php提交页代码<?
error_reporting(0);
$mysql_servername = "127.0.0.1";
$mysql_username = "root";
$mysql_password ="123456";
$mysql_database ="first";
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);

$U_name=$_POST['user_name'];
$U_passowrd=$_POST['user_password'];

if ($U_name && $U_passowrd){
$sql = "SELECT * FROM admin WHERE U_name = '$U_name' and U_password='$U_passowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
header("location='c.php'");
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}else {
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}

?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-31
主页面:index.php <form name="form1" action="login.php" method="post" onsubmit="return check()"><!--这里注意onclick的用法-->
账号:<input name="adminAccount" type="text" />

密码:<input type="password" name="adminPass" />

输入验证码:<input type="text" name="validate" />
< br />
<input type="submit" value="登陆" /><input type="reset" value="重置">
</form>判断页面:login.php<?php
//再连库判断账号密码
require_once("../inc/dbconfig.php");
$adminAccount=$_POST['adminAccount'];
$adminPass=md5($_POST['adminPass']);
$sql="select * from admin where adminAccount='$adminAccount' and adminPass='$adminPass'";
$result=mysql_query($sql) or die($sql);
$rows=mysql_num_rows($result);
if($rows==0){
?>
<script language="javascript">
alert("管理员账号密码错误!");
window.location="index.php";
</script>
<?
exit();
}
//将管理员账号赋值给session
$_SESSION['adminAccount']=$adminAccount;
?>
<script language="javascript">
window.location="command.php";
</script>配置文件自己来就行了!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网