分享

PHP登陆页面完整代码

 quasiceo 2014-05-12

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="./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="./css/login.css">
<script type="text/javascript" src="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" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
  </tr>
  <tr>
    <td height="25" align="right">密码:</td>
    <td><input name="password" type="password" id="password"  onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
  </tr>
  <tr>
    <td height="25"align="right">验证码:</td>
    <td><input name="check" type="text" id="check"  onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="10" /><img src="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;
    }
   
}
?>

/*

效果为*/

posted @ 2012-06-01 11:09 losesea 阅读(13842) 评论(3) 编辑 收藏
评论列表
  
#1楼 2013-02-01 11:30 金英  
您学过php没有?php用var定义变量?javascript的语法吧!$-> db_password?这个你也错了!发到网上的东西,也得负责任吧,OK?
  
#2楼 2013-11-07 10:18 lipisam  
能方便 发截图里面的全部文件 给学习吗? 邮箱2450674172@qq.com
  
#3楼 2014-04-13 11:04 头头0312  
mysql.php是要写类吗?你的类呢?????、class不知道吗?还用var定义变量,你会吗???????

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多