『壹』 用php做登陸注冊頁面
登錄頁:login.php
<?php
include("conn.php");
$username=$_POST['name'];
$password=$_POST['password'];
$yanzheng=$_POST['yanzheng'];
if(isset($_POST['submit']))
{
$sql=("select username,password from member where username='$username' and password='$password'") or die("sql語句執行失敗");
//print_r($sql);
$ar=mysql_query($sql);
if($ar)
{
if($row=mysql_fetch_array($ar))
{
session_start();
if($_POST["yanzheng"])
{
if($yanzheng!=$_session[pic]||$yanzheng=="")
{
echo "驗證碼輸入有誤";
exit;
}
if($yanzheng==$_session[pic])
{
header("location:index.php");
}
}
}
else
{
echo "用戶名或密碼錯誤";
}
}
}
?>
<form action="login.php" method="post">
<table border=1 align=center width=500 height=300 bgColor=#DFFFDF bordercolor=#fffbec>
<tr>
<td colspan=2 align=center>用戶登錄</td>
</tr>
<tr>
<td>用戶姓名:</td>
<td><input type="text" name="name" id="name"/></td>
</tr>
<tr>
<td>用戶密碼:</td>
<td><input type="password" name="password" id="password"/></td>
</tr>
<tr>
<td>驗證碼:</td>
<td><input type="text" name="yanzheng" id="yanzheng"/>
<img src="yanzheng1.php" width="50" height="30"></img>
</td>
</tr>
<tr>
<td colspan=3 align=center>
<input type="submit" name="submit" value="登錄"/>
<input type="reset" name="reset" value="重置"/>
<a href="register.php">注冊</a>
</td>
</tr>
</table>
</form>
注冊頁:register.php
<?php
include("conn.php");
if(isset($_POST['submit'])&&$_POST['submit']) {
if($_POST['username']=='')
{
echo "用戶名不能為空";
exit();
}
if($_POST['password']=='')
{
echo "密碼不能為空";
exit();
}
if($_POST['realpass']!=$_POST['password'])
{
echo "兩次密碼輸入不一致";
exit();
}
$sql="insert into member(username,real_name,password,email,headimg) values('$_POST[username]','$_POST[username]','$_POST[password]','$_POST[email]','')";
$ar=mysql_query($sql);
if($ar)
{
header("location:index.php");
}
else
{
echo mysql_error();
}
}
?>
<body>
<form action="register.php" method="post">
<table border=1 align=center width=500>
<tr>
<td height=40 bgColor=#DFFFDF colspan=2>會員注冊 [<a href="login.php">返回登錄頁</a>]</td>
</tr>
<tr>
<td height=40 bgColor=#fffbec >會員ID</td>
<td><input type="text" name="username" id="username"/></td>
</tr>
<tr>
<td height=40 bgColor=#fffbec>密碼</td>
<td><input type="password" name="password" id="password"/></td>
</tr>
<tr>
<td height=40 bgColor=#fffbec>確認密碼</td>
<td>
<input type="password" name="realpass" id="realpass"/>
</td>
</tr>
<tr>
<td height=40 bgColor=#fffbec>EMAIL</td>
<td><input type="text" name="email" id="email"/>
</tr>
<tr>
<td height=40 bgColor=#fffbec></td>
<td><input type="submit" name="submit" value="注冊"/><input type="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
主頁顯示:index.php
<?php
include("conn.php");
function cutstr($str,$cutleng)
{
$str = $str; //要截取的字元串
$cutleng = $cutleng; //要截取的長度
$strleng = strlen($str); //字元串長度
if($cutleng>$strleng)return $str;//字元串長度小於規定字數時,返回字元串本身
$notchinanum = 0; //初始不是漢字的字元數
for($i=0;$i<$cutleng;$i++)
{
if(ord(substr($str,$i,1))<=128)
{
$notchinanum++;
}
}
if(($cutleng%2==1)&&($notchinanum%2==0)) //如果要截取奇數個字元,所要截取長度范圍內的字元必須含奇數個非漢字,否則截取的長度加一
{
$cutleng++;
}
if(($cutleng%2==0)&&($notchinanum%2==1)) //如果要截取偶數個字元,所要截取長度范圍內的字元必須含偶數個非漢字,否則截取的長度加一
{
$cutleng++;
}
return substr($str,0,$cutleng);
}
?>
<html>
<head>
<script type="text/javascript">
function All(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked; //得到那個總控的復選框的選中狀態
}
function Item(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; i<aa.length; i++)
if(!aa[i].checked) return;
all.checked = true;
}
}
</script>
</head>
<?php
include("conn.php");
if(isset($_POST['del']))
{
$mm = $_POST["selected"];
$id =implode(",",$mm);
$sql = "delete from forums where id in(".$id.")";
//echo $sql;
$result=mysql_query($sql);
echo $result?"刪除成功":"刪除失敗";
}
?>
<table style="BORDER-BOTTOM-WIDTH: 1px; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=600 align=center border=1 bordercolor=#ddddff>
<tr align=middle>
<td height=40 bgColor=#DFFFDF colspan=3>論壇列表</td>
</tr>
<tr>
<td colspan=3><a href="login.php" style="float:right">[退出系統]</a><a href="add_forum.php" style="float:right">[添加論壇]</a></td>
<td></td>
</tr>
<tr align=middle>
<td height=40 bgColor=#DFFFDF width=80>狀態</td>
<td height=40 bgColor=#DFFFDF>論壇</td>
<td height=40 bgColor=#DFFFDF>最後更新</td>
</tr>
<?php
$sql="select * from forums";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
while($row=mysql_fetch_array($result)){
?>
<tr align=middle>
<td bgColor=#fffbec><input type="checkbox" name="selected" value="1"/></td>
<td height=50 bgColor=#fffbec width=300>
<?php
echo "<div><a href=\"forums.php?F=".$row['ID']."\">".$row['forum_name']."</a></div>";
echo cutstr($row['forum_description'],24);//最多顯示24個位元組,12個字,多餘部分用省略號代替
echo "……";
?>
</td>
<td height=50 bgColor=#fffbec><div><?php echo $row['last_post_time']."by".$row['last_post_author']?></div></td>
</tr>
<?php
}
}
else
{
echo "<tr bgColor=#fffbec><td colspan=3>對不起,論壇尚在創建中……</td></tr>";
}
?>
<tr>
<td colspan=3> <input type="checkbox" name="selected" value="1" onclick="All(this,'selected')"/>全選/不全選</td>
</tr>
<tr>
<td><input type="button" name="del" id="del" value="刪除選中項"/>
<?php
?>
</td>
</tr>
</table>
</html>
資料庫你就自己建,望採納~
『貳』 用php的CI框架怎麼寫登錄和注冊
在view里寫login.php,在controller里寫插入資料庫的代碼,同時調用。
『叄』 HTML 代碼 PHP登陸後 頁面跳轉
通常情況下,登錄成功後跳轉到後台框架,登錄失敗則返回到登錄頁面,這一做法與所使用的編程語言關系不大。在檢測到賬號和密碼正確後,會賦予session或cookies。一個簡單的代碼示例如下:
echo"";
這段代碼會在登錄成功後彈出提示框「登陸成功」,並跳轉到admin.php頁面。當然,實際應用中還需要結合具體情況進行調整和完善。這樣的處理方式可以為用戶提供良好的體驗,確保登錄狀態的安全性和准確性。
在登錄過程中,還需要注意處理可能的錯誤情況,如用戶名或密碼錯誤、網路問題等。當檢測到這些錯誤時,應及時將用戶引導回登錄頁面,並提示相應的錯誤信息,以便用戶能夠及時了解問題所在並進行相應的修正。
此外,為了提升用戶體驗,可以考慮在登錄成功後,以更友好的方式告知用戶,例如使用彈窗提示或頁面跳轉,而不是直接跳轉到後台框架。這樣可以減少用戶對系統突然跳轉的不適感,提高系統的可用性。
在實現登錄功能時,除了前端代碼外,還需要確保後端邏輯的正確性。例如,在處理登錄請求時,需要對輸入數據進行嚴格的驗證,防止SQL注入、XSS攻擊等安全問題。同時,也要注意保護用戶的隱私和安全,避免泄露敏感信息。
總之,登錄功能的設計和實現需要綜合考慮用戶體驗、安全性和可用性等多個方面,才能為用戶提供一個安全、便捷的登錄體驗。
『肆』 求寫個比較簡單的php登陸頁面代碼
主頁面:index.php <form name="form1" action="login.php" method="post" onsubmit="return check()"><!--這里注意onclick的用法-->
賬號:<input name="adminAccount" type="text" />
密碼:<input type="password" name="adminPass" />
輸入驗證碼:<input type="text" name="validate" />
< br />
<input type="submit" value="登陸" /><input type="reset" value="重置">
</form>判斷頁面:login.php<?php
//再連庫判斷賬號密碼
require_once("../inc/dbconfig.php");
$adminAccount=$_POST['adminAccount'];
$adminPass=md5($_POST['adminPass']);
$sql="select * from admin where adminAccount='$adminAccount' and adminPass='$adminPass'";
$result=mysql_query($sql) or die($sql);
$rows=mysql_num_rows($result);
if($rows==0){
?>
<script language="javascript">
alert("管理員賬號密碼錯誤!");
window.location="index.php";
</script>
<?
exit();
}
//將管理員賬號賦值給session
$_SESSION['adminAccount']=$adminAccount;
?>
<script language="javascript">
window.location="command.php";
</script>配置文件自己來就行了!
『伍』 求一個php登陸界面和圖片驗證碼(網址也可以)
index.php
<?php
session_start();
session_register('SafeCode');
?>
<SCRIPT language=javascript>
<!--
function CheckForm()
{
if(document.Login.u_name.value=="")
{
alert("請輸入用戶名!");
document.Login.u_name.focus();
return false;
}
if(document.Login.u_pass.value == "")
{
alert("請輸入密碼!");
document.Login.u_pass.focus();
return false;
}
if (document.Login.CheckCode.value==""){
alert ("請輸入您的驗證碼!");
document.Login.CheckCode.focus();
return(false);
}
}
//-->
</SCRIPT>
<script language="javascript">
var vimg_src = "../inc/code.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
vimg.src = vimg_src + "?" + Math.random();
}
</script>
<?php
if ($deng){
if($CheckCode != $_SESSION['SafeCode'] || empty($CheckCode)){
echo "<script>alert('校驗碼不正確!');window.location.href='index.php';</script>";
exit;
}
$u_pass1=md5($u_pass);
$sql = "select * from user where name='$u_name' and pass='$u_pass1' limit 0,1";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)){
$_SESSION['u_admin_name'] = $row['u_name'];
echo "<script>window.location.href='main.php';</script>";
exit;
}
echo "<script>alert('用戶名或密碼不正確!');window.location.href='index.php';</script>";
exit;
}
?>
<TABLE cellSpacing=0 cellPadding=0 width=561 border=0>
<FORM name=Login onSubmit="return CheckForm();" action="index.php?deng=deng" method=post target=_parent>
<TBODY>
<TR>
<TD width=75 rowSpan=2>用戶登錄</TD>
<TD width=126><FONT color=#043bc9>用戶名稱:</FONT></TD>
<TD width=39 rowSpan=2></TD>
<TD width=131><FONT color=#043bc9>用戶密碼:</FONT></TD>
<TD colspan="2"><font color=#043bc9>驗證碼:</font></TD>
<TD colSpan=2 rowspan="2"><input type="submit" value="提交"></TD>
</TR>
<TR>
<TD><INPUT name=u_name></TD>
<TD><INPUT name=u_pass type=password ></TD>
<TD width="33"><input maxlength=4 size=6
name=CheckCode></TD>
<TD width=53><font color=#00cc33><a href='javascript:chg_vimg();' tabindex='-1' ><img src=code.php id=vimg title="看不清換一個!" border="0"></a></font></TD>
</TR></TBODY>
</FORM>
</TABLE>
code.php
<?
//checkNum.php
session_start();
function random($len)
{
$srcstr="abcdefghijkrmnopqrstuvwxyz"; //+0123456789
mt_srand();
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,25)];//35
}
return $strs;//strtoupper()函數轉換為大寫
}
$str=random(4); //隨機生成的字元串
$width = 40; //驗證碼圖片的寬度
$height = 17; //驗證碼圖片的高度
@header("Content-Type:image/png");
$_SESSION["SafeCode"] = $str;
//echo $str;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//模糊點顏色
$pix=imagecolorallocate($im,187,230,247);
//字體色
$font=imagecolorallocate($im,41,163,238);
//繪模糊作用的點
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 2, 0,$str, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
$_SESSION["SafeCode"] = $str;
?>
『陸』 如何用php製作登陸頁面
在login.php那裡,在$_SESSION['username']=$username;後面加 $_SESSION['Aname']=$row['Aname'];
check.php則改成
<?php
session_start();
$Aname=@$_SESSION['Aname'];
if ($Aname)
{
echo"歡迎您".$Aname."!";
}
else
echo "<script language='javascript'>alert('您沒有許可權查看!');location='login.php';</script>";
?>
是否可以解決您的問題?
『柒』 php中在進入一個界面不登陸用戶的情況下顯示需要登錄的彈窗,並且返回登錄界面
在基礎控制器中判斷這個用戶是否登陸,如果沒有登錄就彈窗提示,並跳轉到登錄頁面