html网页html注册登录验证时用户信息如何验证

php实现的简单登陆程序,带html代码和登录验证程序
我的图书馆
php实现的简单登陆程序,带html代码和登录验证程序
最新php实现的简单登陆程序,带html代码和登录验证程序
以下是为大家整理的最新的文章,希望大家能够喜欢!
html代码:
&form action="verify.php" method="post"&
&&& User Name:&br&
&&& &input type="text" name="username"&&br&&br&
&&& Password:&br&
&&& &input type="password" name="password"&&br&&br&
&&& &input type="submit" name="submit" value="Login"&
verify.php
if(isset($_POST['submit'])){
&&& $dbHost = "localhost";&&&&&&& //Location Of Database usually its localhost
&&& $dbUser = "xxxx";&&&&&&&&&&& //Database User Name
&&& $dbPass = "xxxxxx";&&&&&&&&&&& //Database Password
&&& $dbDatabase = "db_name";&&& //Database Name
&&& $db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database.");
&&& //Connect to the databasse
&&& mysql_select_db($dbDatabase, $db)or die("Couldn't select the database.");
&&& //Selects the database
&&& The Above code can be in a different file, then you can place include'filename.php'; instead.
&&& //Lets search the databse for the user name and password
&&& //Choose some sort of password encryption, I choose sha256
&&& //Password function (Not In all versions of MySQL).
&&& $usr = mysql_real_escape_string($_POST['username']);
&&& $pas = hash('sha256', mysql_real_escape_string($_POST['password']));
&&& $sql = mysql_query("SELECT * FROM users_table&
&&&&&&& WHERE username='$usr' AND
&&&&&&& password='$pas'
&&&&&&& LIMIT 1");
&&& if(mysql_num_rows($sql) == 1){
&&&&&&& $row = mysql_fetch_array($sql);
&&&&&&& session_start();
&&&&&&& $_SESSION['username'] = $row['username'];
&&&&&&& $_SESSION['fname'] = $row['first_name'];
&&&&&&& $_SESSION['lname'] = $row['last_name'];
&&&&&&& $_SESSION['logged'] = TRUE;
&&&&&&& header("Location: users_page.php"); // Modify to go to the page you would like
&&& }else{
&&&&&&& header("Location: login_page.php");
}else{&&& //If the form button wasn't submitted go to the index page, or login page
&&& header("Location: index.php");&&&&
users_page.php
session_start();
if(!$_SESSION['logged']){
&&& header("Location: login_page.php");
echo 'Welcome, '.$_SESSION['username'];
推一荐:&&|&&
喜欢该文的人也喜欢HTML页面登录时的JS验证方法
&更新时间:日 15:55:09 & 作者:
这篇文章主要介绍了HTML界面登录时的JS验证方法,需要的朋友可以参考下
开发一个注册的HTML页面, 用于搜集用户的注册信息。包括: 姓名(不能为空), 年龄(必须超过17岁), 体重(30-150kg), 班级(下拉列表),登陆密码(至少8位长)、确认密码(和登录密码一致),Email(不能为空) , 电话,QQ, 个人简历等信息。 并针对这些表的元素来创建相应的验证,如果检测到错误, 在输入框后面用红色的字显示错误。要用到前面几节学习过的单行文本输入框text、下拉列表框select、密码输入框password、多行文本输入框textarea。这是一个较实用的用户注册表单.。 register.html:
代码如下: &!doctype html& &html& &head& &meta charset="utf-8"& &title&实验2&/title& &link href="check.css" rel="stylesheet" type="text/css"& &script type="text/javascript" src="load.js"& &/script& &/head& &!--return validate()和validate()在于是否清空表单--& &body onload="load_greeting()"& &form id="test" align="left" onSubmit="return validate()"& &table& &tr& &td&Name*:&/td& &td&&input type="text" name="Name" id="name" size="20" onChange='check("name")'&&/td& &td id="nameCheck" class="check" hidden="true"&*姓名不能为空&/td& &/tr& &tr& &td&Age:&/td& &td&&input type="text" name="Age" id="age" size="20" onChange='check("age")'&&/td& &td id="ageCheck" class="check" hidden="true"&*年龄不能小于17岁&/td& &/tr& &tr & &td&weight:&/td& &td&&input type="text" name="weight" id="weight" size="20" onChange='check("weight")'&&/td& &td id="weightCheck" class="check" hidden="true"&*体重范围为30~150KG&/td& &/tr& &tr& &td&Class:&/td& &td&&select id="class" name="class"& &option&class0&/option& &option&class1&/option& &option&class2&/option& &option&class3&/option& &/select& &/td& &/tr& &tr& &td&Password*:&/td& &td&&input type="password" name="Password" id="password" size="20" onChange='check("password")'&&/td& &td id="passwordCheck" class="check" hidden="true"&*password length less than 8&/td& &/tr& &tr& &td&Confirm Password*:&/td& &td&&input type="password" name="cpassword" id="cpassword" size="20" onChange='check("cpassword")'&&/td& &td id="cpasswordCheck" class="check" hidden="true"&*Two passwd is not same&/td& &/tr& &tr & &td&Email*:&/td& &td&&input type="email" name="email" id="email" size="20" onChange='check(this.id)'&&/td& &td id="emailCheck" class="check" hidden="true"&*电子邮件名非法!&/td& &/tr& &tr& &td&TEL:&/td& &td&&input type="text" name="TEL" id="TEL" size="20"&&/td& &/tr& &tr& &td&QQ:&/td& &td&&input type="text" name="QQ" id="QQ" size="20"&&/td& &/tr& &tr& &td&Personal Information:&/td& &td&&textarea rows="10" cols="19"&&/textarea&&/td& &/tr& &tr& &td colspan="3"& &input type="submit" name="submit"& &input type="reset" name="reset"& &/td& &/tr& &/table& &/form& &/body& &/html&
check.css:
代码如下: td.check{ color:#C00; font-weight: }
代码如下: function check(str) { var x = document.getElementById(str); var y = document.getElementById(str+"Check"); //alert("check!"); if(str=="name") { if(x.value=="") y.hidden = else y.hidden = } else if(str=="age") { if(isNaN(x.value) || x.value & 17) y.hidden = else y.hidden = } else if(str=="weight") { x = x. if(isNaN(x) || x & 30 || x & 150) y.hidden = else y.hidden = } else if(str=="password") { x = x.value. if(x & 8) { y.hidden = //alert("check!"); } else y.hidden = } else if(str=="cpassword") { var z = document.getElementById("password"). x = x. if(x != z) y.hidden = else y.hidden = } else if(str=="email") { x = x.value.indexOf("@") if(x == -1) y.hidden = else y.hidden = } return y. } function validate() { var arr=["name", "age", "weight", "password", "cpassword", "email"]; var i = 0; submitOK = while(i &= 5) { if(!check(arr[i])) { alert(arr[i]+" wrong!"); submitOK =
} i++; } if(submitOK) { alert("提交成功!");
} else { alert("提交失败");
} } function load_greeting() { //alert("visit \n"); }
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具博客分类:
最近坛子里接连出现基于httpclient登录网站的帖子,也凑个热闹,分享一点基于htmlunit的登录经验谨以此文祭奠我刚刚逝去的鼠标----------------------------------------------分割线--------------------------------------------------- 目前最新版本2.7( Foxswily本人确认)基于httpclient封装(甚至已经做好启用httpclient4的准备),模拟浏览器操作,JavaScript支持较全面,包括主流的jQuery类库,这也是它的强大之处,一般网站的JS屏蔽可以轻松突破。举例说明
//创建浏览器,可以选择IE、FF等等
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_7);
//获取某网站页面
HtmlPage page = client.getPage("http://xxx.com");
//获取某页面元素,可通过id或name,(具体方式很多 --Foxswily)
HtmlElement elmt = page.getElementById("someid");
//HtmlElement elmt = page.getElementByName("somename");
//此例以文本框为例,先点击,再输入,完全跟真浏览器行为一致
elmt.click();
elmt.type("somewords");
//获取按钮
HtmlButton loginBtn = (HtmlButton)page.getElementById("btnId");
//点击并获得返回结果
Page resultPage = loginBtn.click();
//结果拿到了,想干啥您随意
log.debug(resultPage.getWebResponse().getContentAsString());
沿着这个思路展开一下,模拟登录不再需要破解什么js逻辑,用户实际做什么代码就模拟什么,轻松多了
额外的友情提示,Foxswily本人曾在登录用户量众多的discuz论坛时发现个小问题(已提交)造成登录后跳转失效,如有雷同参照解决吧问题描述
HtmlPage.executeRefreshIfNeeded()when html header has meta like "&META HTTP-EQUIV="Refresh" CONTENT="3 URL=http://www.some.org/some.html"&" it throws NumberFormatException.cause there is no ";" after "3" in the content.some forum sites have this bad writting html page.大意就是,自动跳转格式有问题,htmlunit解析不了,直接Exception了,改写HtmlPage的一个方法后通过。
private void executeRefreshIfNeeded() throws IOException {
// If this page is not in a frame then a refresh has already happened,
// most likely through the JavaScript onload handler, so we don't do a
// second refresh.
final WebWindow window = getEnclosingWindow();
if (window == null) {
final String refreshString = getRefreshStringOrNull();
if (refreshString == null || refreshString.length() == 0) {
int index = refreshString.indexOf(";");
final boolean timeOnly = (index == -1);
if (timeOnly && refreshString.indexOf(" ") == -1) {
// Format: &meta http-equiv='refresh' content='10'&
time = Double.parseDouble(refreshString);
} catch (final NumberFormatException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Malformed refresh string (no ';' but not a number): "
+ refreshString, e);
url = getWebResponse().getRequestSettings().getUrl();
if (refreshString.indexOf(";") == -1) {
index = refreshString.indexOf(" ");
// Format: &meta http-equiv='refresh'
// content='10;url=http://www.blah.com'&
time = Double.parseDouble(refreshString.substring(0, index).trim());
} catch (final NumberFormatException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Malformed refresh string (no valid number before ';') "
+ refreshString, e);
index = refreshString.toLowerCase().indexOf("url=", index);
if (index == -1) {
if (LOG.isErrorEnabled()) {
LOG.error("Malformed refresh string (found ';' but no 'url='): "
+ refreshString);
final StringBuilder buffer = new StringBuilder(refreshString
.substring(index + 4));
if (buffer.toString().trim().length() == 0) {
// content='10; URL=' is treated as content='10'
url = getWebResponse().getRequestSettings().getUrl();
if (buffer.charAt(0) == '"' || buffer.charAt(0) == 0x27) {
buffer.deleteCharAt(0);
if (buffer.charAt(buffer.length() - 1) == '"'
|| buffer.charAt(buffer.length() - 1) == 0x27) {
buffer.deleteCharAt(buffer.length() - 1);
final String urlString = buffer.toString();
url = getFullyQualifiedUrl(urlString);
} catch (final MalformedURLException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Malformed URL in refresh string: " + refreshString, e);
final int timeRounded = (int)
getWebClient().getRefreshHandler().handleRefresh(this, url, timeRounded);
浏览 15076
论坛回复 /
(24 / 20860)
看懂了HtmlUnit自然知道这种提交和普通按钮没什么区别,仅仅在于你取的是Link还是Button
那个问题用htmlpage.executeJavaScript(script code)解决了,但最近遇到一个错误(用的是HtmlUnit 2.8):
警告: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://www.ibcbet.com/commjs/ieupdate.js', but got 'application/x-javascript'.
似乎是个BUG,htmlunit作者承认的
Foxswily 写道验证码是所有类似工具都要面对的问题,我尝试两种方式解决
1.图像识别,这个可以单独拿来研究了,算法难度不小,外加现在的图片干扰越来越邪乎,不好实现。
2.显示图片人工解决,个人推荐这方式。毕竟登录一次可以程序保障长期在线,性价比高的方案:)
第二个解决方法,能不能帖段代码...
1,把登陆页面刷出来。
2,肉眼识别出验证码。
3,把验证码写死到程序里去。
是不是这样
验证码是所有类似工具都要面对的问题,我尝试两种方式解决
1.图像识别,这个可以单独拿来研究了,算法难度不小,外加现在的图片干扰越来越邪乎,不好实现。
2.显示图片人工解决,个人推荐这方式。毕竟登录一次可以程序保障长期在线,性价比高的方案:)
第二个解决方法,能不能帖段代码...
& 上一页 1
浏览: 62414 次
来自: 北京
huang_yong 写道XStream 对于 List&lt ...
XStream 对于 List&Map&Strin ...
我登录人人之类的都登录不上去,无法跳转请问一下是什么问题啊
jiangshuiy 写道JsonHierarchicalSt ...
JsonHierarchicalStreamDriver,可是 ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'public class FormServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/charset=utf-8");
PrintWriter out = response.getWriter();
out.println("&!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"&");
out.println("&HTML&");
out.println("
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&");
out.println("
String form = "&form action='LoginCodeServlet' method='post'&"+
"Name:&input type='text' name='name'/&&br/&"+
"Pwd:&input type='password' name='pwd'/&&br/&"+
"验证码:&input type='text' name='code'/&&img src='ImgServlet'&&/img&&br/&"+
"&input type='submit' value='登录'/&
out.println(form);
out.println("
&/BODY&");
out.println("&/HTML&");
out.flush();
out.close(); }
---------------------------------------------------------------------------------------------------------
public class LoginCodeServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {doPost(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/charset=utf-8");
PrintWriter out = response.getWriter();
out.println("&!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"&");
out.println("&HTML&");
out.println("
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&");
out.println("
String code = request.getParameter("code");//用户输入的code
String sCode = (String) request.getSession().getAttribute("sCode");//放在session中真实code
if(sCode==null || !sCode.equals(code)){
out.println("验证码错误!");
//验证码正确,然后再获取用户名和密码,到后台进行用户信息验证
String name = request.getParameter("name");
String pwd = request.getParameter("pwd");
if(name!=null && !name.trim().equals("") &&
pwd!=null && !pwd.trim().equals("")){
System.out.println("到后台数据库进行信息验证:"+name+","+pwd);
out.println("登录成功:"+name+","+pwd);
out.println("验证码正确,但Name或Pwd信息未输全");
//※验证码用过一次之后,就要让它失效!!!否则容易被黑
request.getSession().removeAttribute("sCode");//清除容器中的属性
out.println("
&/BODY&");
out.println("&/HTML&");
out.flush();
out.close(); }
-------------------------------------------------------------------------------------------------------------------
public class ImgServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpg");
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setFont(new Font("a", Font.BOLD, 18));
Random r = new Random();
int a = r.nextInt(10000);
//把正确的验证码存储到session中
request.getSession().setAttribute("sCode", ""+a);
g.drawString(""+a, 0, h);
g.dispose();
ImageIO.write(img, "JPEG", response.getOutputStream()); }}
----------------------------------------------------------------------------------------------------------------------
&a href="FormServlet"&用户登录--验证码技术演示&/a&
阅读(...) 评论() 上传我的文档
 上传文档
 下载
 收藏
粉丝量:54
该文档贡献者很忙,什么也没留下。
 求助此文档
利用html和javascript技术写的简单用户注册界面(网页)表单验证
下载积分:1200
内容提示:利用html和javascript技术写的简单用户注册界面(网页)表单验证
文档格式:DOC|
浏览次数:1227|
上传日期: 20:35:45|
文档星级:
全文阅读已结束,此文档不支持下载
发布找文档任务
该用户还上传了这些文档
利用html和javascript技术写的简单用户注册界面(网
关注微信公众号

我要回帖

更多关于 html登录注册网页代码 的文章

 

随机推荐