首页 > 代码库 > PHP登陆页面完整代码
PHP登陆页面完整代码
/*
包括的文件
*/
/*
login.php
*/
<?php
require(‘./mysql.php‘);
$username=$_REQUEST[‘username‘];
$passwd=$_REQUEST[‘passwd‘]
session_start();
$_SESSION[‘s_username‘]=$username;
$query_user="select * from user where username = ‘$username‘ and passwd = ‘$passwd‘";
$db=new mysql();//实例化类mysql
$result = $db->query_exec($query_user);//验证用户
$num_results=$result->num_rows;//取得数据库中的记录行
if($num_results==0)
{
echo ‘login fail!!‘;
?>
<p><a href="http://www.mamicode.com/template/login.htm">返回登陆</a></p>
<?php
}else{
header("Location: ./index.php");
}
?>
/*
templates/login.tpl
*/
<html>
<head>
<meta http-equiv="text/html;charset=‘utf-8‘">
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/css/login.css">
<script type="text/javascript" src="http://www.mamicode.com/js/face.js"></script>
</head>
<body>
<table width="400px" height="208" border="0" cellpadding="0" cellspacing="0" >
<form id="login" name="login" method="post" action="a.php" onSubmit="">
<tr>
<td height="25" align="right">用户名:</td>
<td><input name="name" type="text" onm ouseover="this.style.backgroundColor=‘#ffffff‘" onm ouseOut="this.style.backgroundColor=‘#e8f4ff‘" size="15" /></td>
</tr>
<tr>
<td height="25" align="right">密码:</td>
<td><input name="password" type="password" id="password" onm ouseover="this.style.backgroundColor=‘#ffffff‘" onm ouseOut="this.style.backgroundColor=‘#e8f4ff‘" size="15" /></td>
</tr>
<tr>
<td height="25"align="right">验证码:</td>
<td><input name="check" type="text" id="check" onm ouseover="this.style.backgroundColor=‘#ffffff‘" onm ouseOut="this.style.backgroundColor=‘#e8f4ff‘" size="10" /><img src="http://www.mamicode.com/code.php" id="code" /></td>
</tr>
/*
mysql.php
*/
<?php
var $db_host = ‘localhost‘;
var $db_username= ‘root‘;
var $db_password= ‘123‘;
var $db_database= ‘new‘;
$db =mysql_connect($ db_host,$db_username,$-> db_password,$-> db_database);
if (mysqli_connect_errno()) {
echo "连接数据库失败!";
exit;
}
return $db;
}
}
?>
/*
效果为*/
PHP登陆页面完整代码