Ⅰ 如何用php做個登陸界面
你可以做一個簡單的例如你只有用戶名和密碼即可那麼你先在資料庫(以mysql為例)中建表例如叫做user 欄位為 id name pass分別是編號、用戶名、密碼長度分別是int(8) a_t(自動編號) 主鍵,varchar(50) ,varchar(50) 你可以添加一個測試數據 例如 1,admin,admin//說明密碼這里不說加密的問題,用明文實現 登錄頁面的代碼:login.php<html><head><title>用戶登錄</title></head><body><form action="checklogin.php" name="loginform" method="post">用戶名:<input name="name" type="text"><br>密 碼:<input name="password" type="password"><br><input value="登錄" type="submit"><br></form></body></html> checklogin.php代碼(檢測登錄): $name=$_POST[name];$pass=$_POST[password];session_start();//這個可以維持登錄狀態,可以參照session的使用
//登錄檢查函數 function login_state($uid,$user_shell){ $sql="SELECT * FROM `user` WHERE `name`='$name'";
$query=@mysql_query($sql) or die(mysql_error());
$us=is_array($row=@mysql_fetch_array($query));
$user_shell=$us ? $user_shell==$row[password]:FALSE;
if($user_shell){ echo "<script>alert('登錄成功');</script>";
return $row;
}else{
echo "<script>alert('您暫時不能瀏覽該頁面,請先登錄');location.href='login.php';</script>";
} }login_state($name,$password);?>
希望可以幫到您,如果還有問題可以聯系2458285853
Ⅱ 如何用php實現自動登錄別的網站
首先在用戶第一次登陸的時候,如果勾選了一周內免登陸,則在登陸操作完成之後,存儲一個自動登錄的cookie,這個cookie可以是「$value是用戶的"id"加一個"隨機碼"組成的字元串加密處理後的數據」這個隨機碼是存放在資料庫里的用戶表裡面,作為用戶下次自動登陸時驗證。也可以是更加高端的數據
Ⅲ 用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實現一個賬號不能多個用戶同時登陸
我現在的用法是:
1、每個人登錄的時候會生成一個隨機碼(隨機碼保存在資料庫中);
2、客戶端cookies不保存用戶名,只保存隨機碼;
3、賬號在任何的地方登錄時便會執行第一二部,之前的登錄就會失效;
4、就這樣就實現了你的功能;
擴展:
5、可以設置網頁最後更新的時間,並且超過一定的時間後就過期;
6、隨機碼要長一點才不會重復,我現在用的64進制32位,這樣幾乎不可能重復;
7、另外客戶端不保存用戶名和密碼只存存隨機碼相對來說安全性也要高些;
Ⅳ 在線等!急! 用PHP編寫程序,實現簡單的用戶登錄頁面 (1)製作login.html用戶登錄頁面,效果圖如下:
login.html
<form action="login.php" method="post" name="formUser" >
<table width="100%" border="0" align="left" cellpadding="5" cellspacing="3">
<tr>
<td width="25%" align="right">用戶名:</td>
<td width="65%">
<input name="username" type="text" size="25" id="username" />
</td>
</tr>
<tr>
<td align="right">登陸密碼:</td>
<td>
<input name="password" type="password" id="password1" style="width:179px;" />
</td>
</tr>
<tr>
<td align="right">確認密碼:</td>
<td>
<input name="confirm_password" type="password" id="conform_password" style="width:179px;"/>
</td>
</tr>
<tr>
<td align="right">選擇性別:</td>
<td>
<input name="rd1" type="radio" size="25" id="rd1" value="男" checked/>
<input name="rd2" type="radio" size="25" id="rd2" value="男"/>
</td>
</tr>
<tr>
<td align="right">個人愛好:</td>
<td>
<input name="ck1" type="checkbox" size="25" id="ck1" value="音樂" checked/>
<input name="ck2" type="checkbox" size="25" id="ck2" value="游戲"/>
<input name="ck3" type="checkbox" size="25" id="ck3" value="電影"/>
</td>
</tr>
<tr>
<td align="right">備注信息:</td>
<td>
<input name="t1" type="text" size="25" id="t1" value="" />
</td>
</tr>
<tr>
<td >
<input name="Submit" type="submit" value="普通提交按鈕" >
</td>
<td>
<input name="btn1" type="btn" value="重置按鈕" >
</td>
</tr>
</table>
</form>
login.php
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
if (strlen($password) < 6)
{
show_message($_LANG['passport_js']['password_shorter']);
}
if (strpos($password, ' ') > 0)
{
show_message($_LANG['passwd_balnk']);
}
if (register($username, $password) !== false)
{
/*把新注冊用戶的擴展信息插入資料庫*/
$sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id'; //讀出所有自定義擴展欄位的id
$fields_arr = $db->getAll($sql);
$extend_field_str = ''; //生成擴展欄位的內容字元串
foreach ($fields_arr AS $val)
{
$extend_field_index = 'extend_field' . $val['id'];
if(!empty($_POST[$extend_field_index]))
{
$temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index];
$extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . compile_str($temp_field_content) . "'),";
}
}
$extend_field_str = substr($extend_field_str, 0, -1);
if ($extend_field_str) //插入注冊擴展數據
{
$sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str;
$db->query($sql);
}
}
else
{
$err->show($_LANG['sign_up'], 'login.php?act=login');
}
Ⅵ PHP+SQLserver製作一個簡單的登錄功能。
<!-- content starts -->
<?php
if(isset($_POST['add']))
{
date_default_timezone_set('Etc/GMT-8');
$txtname=$_POST['username'];
$txpassword=$_POST['userpwd'];
$txtvalue=$_POST['quxnain'];
$sqlstr = "select * from T1_user where name='".$txtname."'and password=".$txpassword.";";
$conn = mysql_connect("192.168.0.3","root","root");//此處替換用戶名和密碼
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
$result = mysql_query($sqlstr);
$rs=mysql_fetch_array($result);
if($rs)
{
echo "<script>alert('登錄成功!')</script>";
if($txtvalue==1)
echo "<meta http-equiv=refresh content='0;url=../face.php'>";
else
echo "<meta http-equiv=refresh content='0;url=welcome.htm'>";
}
else
echo "<script>alert('用戶名或密碼錯誤!')</script>";
}
?>
<body>
<div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
<img src="images/真煩人.gif" height="100%" width="100%"></img>>
</div>
<div style='height=100'></div>
<form name="form1" method="post" enctype="multipart/form-data" action="" onSubmit="return check()">
<div style="background-image:url(images/登錄小窗口.jpg);margin-left:150px;margin-top:140px;width:542px;height:220px">
<table width="449" height="139" style="margin-left:50px;margin-top:55px;">
<tr>
<td width="187">用戶名: <input name=username type=text class=radio0 size=19></td>
<td width="30" style="width:70px;"></td>
<td width="216"><button name="add" type="submit" style="background-image:url('images/登陸按鈕.jpg');width:210px;height:43px"></button></td>
</tr>
<tr></tr>
<tr>
<td>密 碼:<input name=userpwd type=password class=radio0 size=20></td>
<td></td>
<td></td>
</tr>
<tr>
<td >權 限:<select name="quxnain" style="width:90px">
<option value="1">用戶</option>
<option value="2">管理員</option>
</select></td>
<td></td>
<td><button type="reset" style="background-image:url('images/注冊按鈕.jpg');width:210px;height:43px" onClick="location='register.php'"></button></td>
</tr>
</table>
</div>
</form>
</body>
</html>
拿走用吧
Ⅶ 如何用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登陸後跳轉到登陸前頁面實現思路及代碼
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">";
Ⅸ PHP中如何實現手機號或郵箱登錄高手指點
是否是用戶注冊時,填寫手機和郵箱還有密碼,手機號和郵箱在表不同欄位下,而登錄時只需要在一個輸入框填寫,實現無論手機號還是郵箱都能登錄是嗎?
簡單笨點的方法就是取到這個值,分別和手機號欄位\郵箱欄位匹配,找到了就是這個用戶,沒找到就是手機號或郵箱錯誤.
在一個方法,這個值在控制層表單驗證時判斷是否是正確的手機號,或者郵箱,然後判斷後去進行用戶驗證就可以了啊