『壹』 php登陸頁面完整代碼
PHP登陸後跳轉到登陸前頁面,利用$_SERVER全局變數可以實現這個功能,下面有個不錯的示例,希望對大家有所幫助
最近手上一個小項目讓我接觸到PHP編程,簡單的登陸功能已經OK。可是在實際使用的時候發現一個問題:用戶A發送一個鏈接給用戶B,B打開時頁面提示登陸,可是登陸成功後,卻跳轉到了首頁,而並不是A發送的鏈接。為了有更好的用戶體驗,B登陸成功後應該自動跳轉到登陸前的鏈接。查了PHP幫助手冊,利用$_SERVER全局變數可以實現這個功能。 $_SERVER是PHP的一個超全局變數,關於$_SERVER變數的詳細解釋可以參考:http://www.php.net/manual/zh/reserved.variables.server.php 具體實現方法為:在提示用戶登錄的同時,在session或者cookie中記錄下請求頁面的URL;登錄驗證成功後在跳轉回該URL。 checklogin.php 代碼如下: session_start(); if (!isset ($_SESSION['login_ok'])) { echo "<script language=javascript>alert ('要訪問的頁面需要先登錄。');</script>"; $_SESSION['userurl'] = $_SERVER['REQUEST_URI']; echo '<script language=javascript>window.location.href="login.php"</script>'; } login.php 代碼如下: session_start(); //此處省略了賬號密碼驗證代碼,驗證OK再執行下面代碼 if (isset ($_SESSION['userurl'])) { //會話中有要跳轉的頁面 $url = $_SESSION['userurl']; } else { //沒有要跳轉的頁面,則轉到首頁 $url = "home.php"; } //0.5s後跳轉 echo "<meta http-equiv="refresh" content="0.5;url=$url">";
『貳』 這是登錄頁面的後台代碼:
我感覺你的代碼很清晰,位置也對(有一點,我覺得判斷驗證碼應該在最先,不過這無所謂,不會影響程序)。是不是session丟失的問題,你可以這樣試試,
<system.web>
<sessionState mode="StateServer" timeout="30"/>
</system.web>
並且手動啟動服務ASP.NET State Service
還有你的母版頁,我寫都是在Init事件中判斷session,因為一個頁面套用了母版頁後,順序是這樣的:先是普通頁的init事件,然後母版頁的init,普通頁的load,母版頁的load
,還有你的!ispostback,我也不太知道對不對,去掉試試。
如果還不行的話,那就不好意思了,小弟能力有限,就當我路過...
『叄』 用html代碼編寫一個簡單的登陸界面
<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登錄</title>
<link href="css/bootstrap.min.css" rel="stylesheet"></head><body><nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./">jsp作業</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.html">登錄</a></li>
</ul>
</div>
</div></nav><div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" target="submitFrame" method="post">
<h2 class="form-signin-heading">登錄到jsp作業</h2>
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail" class="form-control" placeholder="請輸入Email" required autofocus><br>
<label for="inputPassword">密碼</label>
<input type="password" id="inputPassword" class="form-control" placeholder="請輸入密碼" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" checked="checked"> 記住密碼 </label>
</div>
<button type="submit" class="btn btn-primary" id="btn-login">登錄</button>
<a href="reg.html" class="btn btn-default">注冊</a>
</form>
<iframe style="display: none;" name="submitFrame" src="about:blank"></iframe>
</div>
<div class="col-md-4">
</div>
</div>
<script src="js/jquery.min.js"></script></body></html>
『肆』 html網頁設計:一個簡單的登錄界面代碼!
大致形式應該是這樣的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>3</title>
</head>
<body>
<div align="center">
<form action="" name="myform">
<table>
<tr>
<td>用戶名:</td>
<td><input type="text" id="user" /></td>
</tr>
<tr>
<td>密 碼:</td>
<td><input type="text" id="password" /></td>
</tr>
<tr>
<td>驗證碼:</td>
<td align="left"><input type="text" size="5" id="code" /></td>
</tr>
</table>
</form>
<table>
<tr>
<td>
<input type="submit" value="提交" onclick=myfun_submit() />
</td>
<td>
<input type="submit" value="重置" onclick=myfun_reset() />
</td>
</tr>
</table>
</div>
<script type="text/javascript">
function myfun_submit(){
var user_val = document.getElementById("user").value;
var password_val = document.getElementById("password").value;
if(user_val==""){
alert("用戶名不能為空!!");
}else if(password_val==""){
alert("密碼不能為空!!!");
}
}
function myfun_reset(){
document.getElementById("user").value = "";
document.getElementById("password").value = "";
document.getElementById("code").value = "";
}
</script>
</body>
</html>
『伍』 登錄頁面html代碼
<htmlxmlns="http://www.w3.org/1999/xhtml"><head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8">
<title>貴美商城</title>
<linkrel="stylesheet"type="text/css"href="css/global.css">
<linkrel="stylesheet"type="text/css"href="css/layout.css">
<scripttype="text/javascript">
//snameCheck()&&passCheck()
functionvalidateform(){
if(snameCheck()&&passCheck())
returntrue;
else
returnfalse;
}
//ScreenNameValidation
functionsnameCheck(){
varsname=document.getElementsByName("sname")[0].value;
varillegalChars=/W/;
if(sname.length!=0){
if(illegalChars.test(sname)){
document.getElementById("passMsg").innerHTML.replace(/'會員名無效'/,'');
document.getElementById("passMsg").innerHTML='會員名無效';
document.getElementsByName("sname")[0].select();
returnfalse;
}
}
else
{
document.getElementById("userMsg").innerHTML.replace(/'是否忘記輸入會員名?'/,'');
document.getElementById("userMsg").innerHTML='是否忘記輸入會員名?';
document.getElementsByName("sname")[0].focus();
returnfalse
}
if(sname!=="zhangsan"){//驗證會員名必須為張三
document.getElementById("userMsg").innerHTML.replace(/'是否輸入的會員名有錯?'/,'');
document.getElementById("userMsg").innerHTML='是否輸入的會員名有錯?';
document.getElementsByName("sname")[0].focus();
returnfalse;
}
returntrue;
}
functionpassCheck(){
varuserpass=document.getElementsByName("pass")[0].value;
varillegalChars=/[W_]/;//allowonlycharactorsandnumbers
//CheckifPasswordfieldisblank.
if(userpass==""){
document.getElementById("passMsg").innerHTML.replace(/'未輸入密碼 "+"請輸入密碼'/,'');
document.getElementById("passMsg").innerHTML='未輸入密碼 "+"請輸入密碼';
document.getElementsByName("pass")[0].focus();
returnfalse;
}
//.
if(userpass.length<6){
document.getElementById("passMsg").innerHTML.replace(/'密碼必須多於或等於6個字元。 '/,'');
document.getElementById("passMsg").innerHTML='密碼必須多於或等於6個字元。 ';
document.getElementsByName("pass")[0].focus();
returnfalse;
}
//.
elseif(illegalChars.test(userpass)){
document.getElementById("passMsg").innerHTML.replace(/'密碼包含非法字元'/,'');
document.getElementById("passMsg").innerHTML='密碼包含非法字元';
document.getElementsByName("pass")[0].select();
returnfalse;
}
if(userpass!=="123456"){//驗證密碼必須為123456
document.getElementById("passMsg").innerHTML.replace(/'密碼錯誤,請重新輸入!'/,'');
document.getElementById("passMsg").innerHTML='密碼錯誤,請重新輸入!';
document.getElementsByName("pass")[0].focus();
returnfalse;
}
returntrue;
}
</script>
<scripttype="text/javascript"charset="utf-8"src="http://cdn.gwdang.com/js/gwdang-notifier-bdext.js"></script></head>
<body>
<divid="container">
<iframeid="header"src="header.htm"width="980"height="136"frameborder="0"scrolling="no"></iframe>
<formaction="login_success"method="post">
<divclass="login">
<ulclass="formf_l">
<h1><imgsrc="images/logintitle.gif"alt="會員登錄"></h1>
<liclass="login_list"><label>會員名:</label><inputtype="text"name="login">(可包含a-z、0-9和下劃線)</li>
<liclass="login_list"><label>密 碼:</label><inputtype="text"name="pwd">(至少包含6個字元)</li>
<liclass="a_c"><imgsrc="images/login.gif"alt="登錄"></li>
<liclass="desc">δ <ahref="#">什麼是安全登錄</a>。</li>
<liclass="desc">δ 香港會員(繁體中文用戶)由此<ahref="#">登入</a></li>
<liclass="desc">δ <ahref="#">密碼安全貼士</a>。</li>
<liclass="desc">δ 防止病毒或者木馬竊取您的賬戶信息,<ahref="#">在線檢查</a>您的電腦是否安全。</li>
</ul>
<h1><imgsrc="images/register.gif"alt="注冊會員"></h1>
<ulclass="asidef_l">
<liclass="regpic"><span>便宜有好貨!</span>超過7000萬件商品任您選。</li>
<liclass="regpicregpic2"><span>買賣更安全!</span>交易超安全。</li>
<liclass="regpicregpic3"><span>免費開網店!</span>輕松賺錢交友。</li>
<liclass="regpicregpic4"><span>超人氣社區!</span>彩活動每一天</li>
<liclass="a_c"><ahref="#"><imgsrc="images/registernow.gif"alt="現在就注冊"></a></li>
<ulclass="reged">
<liclass="regpicregpic5">您已經是會員?<ahref="#">由此登入</a></li>
<liclass="regpicregpic6">繁體中文用戶由此<ahref="#">注冊</a></li>
</ul>
</ul>
</div>
</form>
<iframeid="footer"src="footer.htm"width="980"height="136"frameborder="0"scrolling="no"></iframe>
</div><!--containerend--> <divclass="_bd_ext_tip"style="visibility:hidden;"><spanclass="_bd_ext_search">網路一下</span><spanclass="_bd_ext_open">打開鏈接</span><spanclass="_bd_ext_">復制</span></div></body></html>
『陸』 html登陸界面代碼
實現這個功能要兩個網頁,一個是前台靜態網頁,用兩個文本框分別為t1,t2,一個按鈕active後面寫上你要跳轉的後台網頁的名稱如"houtai.asp"
以下是houtai.asp的代碼
<%
dim
a,b
a=request.from("t1")
b=request.from("t2")
if
a<>admin
then
response.write
"用戶名錯誤"
else
if
b<> 123456
then
response.write
"密碼錯誤"
else
response.redirect
"你要轉到的主頁.asp"
end
if
end
if
%>
『柒』 靜態網頁登錄代碼
最簡單的一個html登錄頁面
就在<form action="">雙引號裡面填你需要跳轉的頁面比如1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="">
<table align="center">
<tr>
<td>
用戶名:
</td>
<td>
<input type="text" name="userName" />
</td>
</tr>
<tr>
<td>
密碼:
</td>
<td>
<input type="password" name="password" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
<td>
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</body>
</html>
『捌』 asp登錄界面源代碼
要是你要的話。我可以發一個文件給你。裡面的內容是一本書的所有例子。包括有
「留言板、注冊和登陸、Blog、小型論壇、新聞發布等等。」
都是ASP版的。只要你建好站點。復制相應的文件到你站點下就行了。
『玖』 jsp登陸界面源代碼
1、login.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登錄頁面</title>
</head>
<body>
<form name="loginForm" method="post" action="judgeUser.jsp">
<table>
<tr>
<td>用戶名:<input type="text" name="userName" id="userName"></td>
</tr>
<tr>
<td>密碼:<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" value="登錄" style="background-color:pink"> <input
type="reset" value="重置" style="background-color:red"></td>
</tr>
</table>
</form>
</body>
</html>
2、judge.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>身份驗證</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc")&& password.equals("123")) {
3、afterLogin.jsp文件
%>
<jsp:forward page="afterLogin.jsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登錄成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("歡迎你:" + name);
%>
</body>
</html>
java web登錄界面源代碼:
1、Data_uil.java文件
import java.sql.*;
public class Data_uil
{
public Connection getConnection()
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="***";
String password="***";
String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";
Connection con=null;
try{
con=DriverManager.getConnection(url,user,password);
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
public String selectPassword(String username)
{
Connection connection=getConnection();
String sql="select *from login where username=?";
PreparedStatement preparedStatement=null;
ResultSet result=null;
String password=null;
try{
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,username);
result=preparedStatement.executeQuery();//可執行的 查詢
if(result.next())
password=result.getString("password");
}catch(SQLException e){
e.printStackTrace();
}finally
{
close(preparedStatement);
close(result);
close(connection);
}
System.out.println("找到的資料庫密碼為:"+password);
return password;
}
public void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
2、login_check.jsp:文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>驗證用戶密碼</title>
</head>
<body>
<jsp:useBean id="util" class="util.Data_uil" scope="page" />
<%
String username=(String)request.getParameter("username");
String password=(String)request.getParameter("password");
if(username==null||"".equals(username))
{
out.print("<script language='javaScript'> alert('用戶名不能為空');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else
{
System.out.println("輸入的用戶名:"+username);
String passwordInDataBase=util.selectPassword(username);
System.out.println("密碼:"+passwordInDataBase);
if(passwordInDataBase==null||"".equals(passwordInDataBase))
{
out.print("<script language='javaScript'> alert('用戶名不存在');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else if(passwordInDataBase.equals(password))
{
out.print("<script language='javaScript'> alert('登錄成功');</script>");
response.setHeader("refresh", "0;url=loginSucces.jsp");
}
else
{
out.print("<script language='javaScript'> alert('密碼錯誤');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
}
%>
</body>
</html>
3、loginSucces.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<hr size="10" width="26%" align="left" color="green">
<font size="6" color="red" >登錄成功 </font>
<hr size="10" width="26%" align="left" color="green">
</body>
</html>
4、user_login.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>登錄界面</title>
</head>
<body background="C:Userswin8workspaceLoginimage\_10.jpg" >
<center>
<br><br><br><br><br><br>
<h1 style="color:yellow">Login</h1>
<br>
<form name="loginForm" action="login_check.jsp" method="post">
<table Border="0" >
<tr >
<td>賬號</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="password">
</td>
</tr>
</table>
<br>
<input type="submit" value="登錄" style="color:#BC8F8F">
</form>
</center>
</body>
</html>