网页代码注册登录怎么写?
- 提问者网友:战魂
- 2021-03-09 14:50
- 五星知识达人网友:三千妖杀
- 2021-03-09 15:22
if(isset($_POST['username']) || isset($_POST['password'])) {
$conn = //.....数据库连接
$sql = sprintf('select id from members where username = "%s" and password = "%s"', $_POST['username'], $_POST['password']);
if(mysql_query($sql)) {
setcookie(//..); //可以设置cookie来记录
$_SESSION['user_id'] = //...也可以设置session来记录
}
}
?>
Tips:这里程序没有加安全过滤和加密,不过登录的主要步骤基本上就这些了
- 1楼网友:时间的尘埃
- 2021-03-09 16:24
怎么没说明sql server 还是access,我给你用access吧:
zhuce中创建字段:user和pasw分别存放用户名和密码:
数据库连接页(conn.asp)
<% db = "sqlmdb.mdb" 'access文件路径(相对) set conn=server.createobject("adodb.connection") '创建连接 strconn="driver={microsoft access driver (*.mdb)};dbq=" & server.mappath(db) '连接字符串 conn.open strconn '打开连接,用完别忘记关哦 if err then'如果有错误,继续! err.clear end if
sub closeconn() '关闭连接,用完请调用此sub关闭 conn.close set conn=nothing end sub %>
注册页:zc.html
<form id="" name="form1" method="get" action="active.asp"> <!--关键在action--> <label> 用户名:<input type="text" name="user" id="user" /> </label> <label> 密码:<input type="password" name="paw" id="paw" />
</label> <label> <input type="submit" name="button" id="button" value="注册" /> <!--关键在name--> </label> <label> <input type="reset" name="button2" id="button2" value="重填" /> <!--关键在name--> </label> </form>
active.asp
<!--#include file="conn.asp"--> <% dim user = request("user")'获取通过get提交的name为user的值 dim pasw = request("paw")''获取通过get提交的name为paw的值 dim sqlstr = "insert into zhuce(user,pasw) value("&user&","&pasw&")" set rs = server.createobject("adobd.recordset") rs.open sqlstr 1,4 rs.close set rs = nothing call closeconn() %>
登陆login.html
代码同注册页:zc.html只改form的active值为login.asp
login.asp
<% dim user = request("user")'获取通过get提交的name为user的值 dim pasw = request("paw")''获取通过get提交的name为paw的值 dim sqlstr = "select * from zhuce while user='"&user&"'" set rs = server.createobject("adobd.recordset") rs.open sqlstr if rs("pasw") = pasw then response.write("<script>alert('登陆成功,点击返回');window.location.history.go(-1)<script>") else response.write("<script>alert('密码错误,点击返回重新填写');window.location.history.go(-1)<script>") end if %>
自己现写的,没测试,理论上可以,自己测试吧,有问题q我