當前位置:首頁 » 編程語言 » php注冊與登錄源碼

php注冊與登錄源碼

發布時間: 2022-07-22 18:10:25

php 用戶注冊源碼

<html>
<head>
<title>用戶注冊</title>
</head>
<body>
<strong>用戶注冊</strong>
<form action="reg.php" method="post">
用戶名稱:<input type="text" name="user"><br>
您的密碼:<input type="password" name="pass"><br>
確定密碼:<input type="password" name="pass2"><br>
<input type="submit" name="submit" value="注冊">
</form>
</body>
</html>
<?php
include ('conn.php'); //這里是您配置的資料庫
if($_POST[submit]){
//判斷用戶名不低於字數
$struser=strlen($_POST[user]);
if($struser <= 4){
echo "<script language=javascript>alert('注冊請輸入5位數以上');history.go(-1);</script>";
exit;
}
//判斷用戶是否存在
$users=$_POST[user];
$result=mysql_query("select * from manage where user='$users'");
$row=mysql_fetch_array($result);
if($_POST[user]==$row[user]){
echo "<script language=javascript>alert('啊!這個名字有人注冊啦!');history.go(-1);</script>";
exit;
}
//判斷用戶密碼兩次輸入正確
if($_POST[pass]!=$_POST[pass2]){
echo "<script language=javascript>alert('親,別耍我啦,兩次密碼怎麼能輸入不一樣呢?');history.go(-1);</script>";
exit;
}
$_POST[pass]=md5($_POST[pass]);
$sql=mysql_query("insert into manage(id,user,pass)
VALUES('','$_POST[user]','$_POST[pass]')
");
if($sql){
echo "<script language=javascript>alert('親,注冊成功!');history.go(-1);</script>";
}
else {
echo "<script language=javascript>alert('對不起,親!注冊失敗咯!');history.go(-1);</script>";
}
exit;
}
mysql_close($con)
?>

我自己寫的 很簡單,100%適合新人。加密了密碼,利用的是MD5

❷ 跪求簡單的php用戶注冊源碼

用$_POST[ ]的方法來獲取用戶表單里填寫的信息,然後再獲取之後用php寫查詢語句,看提交的是否為空,為空則怎樣提示,不為空就查找,查找到了就登錄成功,查不到就登錄信息錯誤。

❸ php網站登錄注冊源碼

//login.php 負責處理用戶登錄與退出動作
if(!isset($_POST['submit'])){
exit('非法訪問!');
}
$username = htmlspecialchars($_POST['username']);
$password = MD5($_POST['password']);

//包含資料庫連接文件
include('conn.php');
//檢測用戶名及密碼是否正確
$check_query = mysql_query("select uid from user where username='$username' and password='$password' limit 1");
if($result = mysql_fetch_array($check_query)){
//登錄成功
$_SESSION['username'] = $username;
$_SESSION['userid'] = $result['uid'];
echo $username,' 歡迎你!進入 <a href="my.php">用戶中心</a>
';
echo '點擊此處 <a href="login.php?action=logout">注銷</a> 登錄!
';
exit;
} else {
exit('登錄失敗!點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試');
}
註:上述源碼是在TP中的登錄驗證方法,供參考!!

❹ 用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注冊源碼

	/**
*賬號注冊
*/
publicfunctioncheckRegister(){
$userName=$_POST['userName'];
//校對驗證碼
$verify=md5($_POST['verify']);
if($verify!=$_SESSION['verify']){
$this->error('驗證碼錯誤!');
}
//校驗賬號是否存在
if(D('User')->checkUserName($userName)){
$this->error('該賬戶已存在,請登錄!','/Login');
}

$type=partUserName($userName);
$yibo_url=$this->deploy['YIBO_YU'];
if($type==1){
$_POST['email']=$_POST['userName'];
$id=D('User')->addData($_POST);
if($id){
//注冊加積分
$this->AddScore($id);
D('Message')->sysSendMessage($id);
$data['uid']=$id;
$data['create_time']=date('Y-m-dH:i:s',time());
$data['come_here']=$_SESSION['fromUrl'];
$data['last_login']=time();
D('UserExtend')->addData($data);
//注冊就要存SESSION此處新添加,後面商量
$_SESSION['userInfo']=D('User')->getDataById($id);
$_SESSION['userInfo']['extend']=D('UserExtend')->getDataByMap(array('uid'=>$id));;
$_SESSION['userInfo']['extend']['pic']=$_SESSION['userInfo']['extend']['pic']?$_SESSION['userInfo']['extend']['pic']:"/Public/image/default.jpg";
//注冊獲取用戶組和積分
$userGroup=D('UserOrgApply')->getUserGroupByUid($id);
$score=D('LevelHistory')->getScoreLevel($id);
$msMap['message.uid']=$id;
$msMap['message.is_read']=0;
$mes['count']=D('Message')->getCount($msMap);
$mes['list']=D("Message")->getMessageConfigList($msMap,'','',"0,5");
//認證信息group不為空則被認證
$_SESSION['userInfo']['group']=$userGroup;
//用戶積分信息
$_SESSION['userInfo']['score']=$score;
$_SESSION['userInfo']['message']=$mes;
//session分發
$result=$this->distributeCheckLogin();
//鏈接注冊引導頁面,需要傳遞第二個參數,$type=1;
$this->sendCheckEmail($_POST['email'],1);
}else{
$this->error('注冊失敗!請稍後再試!');
}
}elseif($type==2){
$_POST['phone']=$_POST['userName'];
$id=D('User')->addData($_POST);
if(!$id){
$this->error('注冊失敗!請稍後再試!');
}
//注冊成功添加積分
$this->AddScore($id);
D('Message')->sysSendMessage($id);
$data['uid']=$id;
$data['create_time']=date('Y-m-dH:i:s',time());
$data['come_here']=$_SESSION['fromUrl'];
D('UserExtend')->addData($data);
//存session
$_SESSION['userInfo']=D('User')->getDataById($id);
$_SESSION['userInfo']['extend']=D('UserExtend')->getDataByMap(array('uid'=>$id));
$_SESSION['userInfo']['extend']['pic']=$_SESSION['userInfo']['extend']['pic']?$_SESSION['userInfo']['extend']['pic']:"/Public/image/default.jpg";
//注冊獲取用戶組和積分
$userGroup=D('UserOrgApply')->getUserGroupByUid($id);
$score=D('LevelHistory')->getScoreLevel($id);
$msMap['message.uid']=$id;
$msMap['message.is_read']=0;
$mes['count']=D('Message')->getCount($msMap);
$mes['list']=D("Message")->getMessageConfigList($msMap,'','',"0,5");
//認證信息group不為空則被認證
$_SESSION['userInfo']['group']=$userGroup;
//用戶積分信息
$_SESSION['userInfo']['score']=$score;
$_SESSION['userInfo']['message']=$mes;
$phone=$userName;
$this->sendPhoneMessage($phone);
$this->success('注冊成功!請激活賬號',"/Login/Index/checkPhone?phone={$phone}");
}else{
$this->error('賬號不合法!');
}
}

❻ 求份php注冊登錄需要邀請碼才能注冊的源碼,要求自己能生成邀請碼,付費也可以。

把邀請碼存在資料庫,注冊的時候查詢一下這個邀請碼存在就可以注冊,不存在就不能注冊。最好加兩個欄位一個被邀請的號碼,一個自己的邀請碼

❼ php會員登錄與注冊的源代碼,及其原理。。。

登錄:判斷輸入的用戶名或密碼是否合法,是則連接資料庫,查詢輸入的用戶名是否存在,密碼是否相同,是則登錄成功!
注冊:所有的注冊信息都要判斷是否合法,是則連接資料庫,檢查用戶輸入的賬號是否已被使用,如果沒被使用,就可以把信息插入資料庫,然後提示成功、跳轉頁面;

❽ php 注冊和登陸頁面代碼+session使用問題:form1.php為注冊頁,form2.php為登陸頁,怎麼用S_SESSION[]

<html><body>
<?php
session_start();
$_SESSION["user"] = $_POST["user1"];
echo $_SESSION["user"] ;
?>
<form name="form2" type="post" action="new111.php">
<table>
<td><input name="user2" type="text"></td>
<td><input name="submit2" type="submit" onClick="return mycheck();" value="提交"></td>
</form>
<script language="javascript">
function mycheck(){
if(form2.submit2.value == "提交"){
if(form2.user2.value == "<?php echo $_SESSION["user1"];?>"){
alert("right!");
}else{
alert("not right!");
}
}

}
</script>
</body>
</html>

熱點內容
腳本lcd 發布:2025-01-31 16:41:02 瀏覽:514
安卓selinux干什麼用的 發布:2025-01-31 16:32:04 瀏覽:530
俠盜獵車手加錢密碼是多少 發布:2025-01-31 15:44:28 瀏覽:661
沒密碼怎麼登微信 發布:2025-01-31 15:33:51 瀏覽:737
c語言死機程序 發布:2025-01-31 15:07:52 瀏覽:18
編程教育裝修 發布:2025-01-31 15:04:38 瀏覽:402
函數和存儲過程的區別 發布:2025-01-31 14:39:12 瀏覽:608
地下室柱子箍筋的加密 發布:2025-01-31 14:36:11 瀏覽:933
手機拍攝視頻在哪個文件夾 發布:2025-01-31 14:34:28 瀏覽:760
sdkpython 發布:2025-01-31 14:23:03 瀏覽:91