登录页面:
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>login</title> <style> body { margin: 0; padding:0; background: #ccc; font-family: '宋体', Simsun; } #wrap { width:290px; margin:17% auto; } #sid { width: 154px; margin-left: -6px; } #sub { margin-left: 65px; } #res { margin-left: 55px; } #vcode{ float:right; } #welcome { font-size:20px; font-family: Comic Sans MS; padding-bottom:5px; } </style></head><body> <div id="wrap"> <div id="welcome">Welcome to mymessbox!</div> <form action="loginok.php" method="post"> 选 择: <select name="loginname" id="sid"> <option value="manager">管理员</option> <option value="user">用户</option> </select> <br> 用户名:<input type="text" name="username" id=""> <br> 密 码:<input type="passWord" name="password" id=""> <br> 验证码:<input type="text" name="vcode" id=""><img src="vcode.php" id="vcode"> <br> <input type="submit" value="login" id="sub"> <input type="reset" value="reset" id="res"> </form> </div></body></html>login.php
登录页面处理:
<?php session_start(); $loginname = $_POST['loginname']; $username = $_POST['username']; $password = $_POST['password']; $vcode = strtolower($_POST['vcode']); $rcode = strtolower($_SESSION['rcode']); MySQL_connect("localhost", "root", "111"); mysql_select_db("mymessbox"); mysql_query("set names utf8"); if ($vcode !== $rcode) { echo "<script>alert('the code is wrong!');window.location.href='login.php'</script>"; } else { if ($loginname == 'manager') { $sql1 = "select username,password from manager where username='$username' and password='$password'"; $ret1 = mysql_query($sql1); $i = mysql_num_rows($ret1); if ($i >=1) { $_SESSION['mgusername'] = $username; echo "<script>alert('login success!');window.location.href='./manager/mg_index.php'</script>"; } else { echo "<script>alert('Login failed!The username or password was wrong!Please login again!');window.location.href='login.php'</script>"; } } else { $sql2 = "select username,password from user where username='$username' and password='$password'"; $ret2 = mysql_query($sql2); $j = mysql_num_rows($ret2); if ($j >=1) { $_SESSION['username'] = $username; echo "<script>alert('login success!');window.location.href='./user/index.php'</script>"; } else { echo "<script>alert('Login failed!The username or password was wrong!!Please login again!');window.location.href='login.php'</script>"; } } }loginok.php
先发这两个吧,虽然还没有完成,还有很多漏洞百出的地方,但是我会一点一点去改。
希望哪个大神在看的时候,能多多指点。不胜感激!