- 1、php實現用戶註冊和登入,不用做效果求大牛指導
- 2、關於php註冊用戶名:
- 3、使用php實現用戶註冊和登錄功能製作 !急求大神幫助!
- 4、php 中註冊用戶之後 怎麼直接登錄?
- 5、PHP怎麼實現登錄和註冊?
- 6、php用戶登錄與註冊
登陸界面 login.php
form action=”logincheck.php” method=”post”
用戶名:input type=”text” name=”user”/br/
密 碼:input type=”password” name=”pass”/br/
input type=”submit” name=”sub” value=”登陸”/
a href=”register.php”註冊/a
/form
登陸處理界面logincheck.php
?php
mysql_connect(‘localhost’,’root’,”);
mysql_select_db(‘test’);
mysql_query(“set names ‘gbk'”);
$nsql=”select username,passwd,nick from userinfo where username = ‘$_POST[user]’ and passwd = ‘$_POST[pass]'”;
$result = mysql_query($nsql);
$num = mysql_num_rows($result);
if($num){
$row = mysql_fetch_array($result);
echo “歡迎您,$row[2]”;
}else{
echo”scriptalert(‘用戶名或密碼不正確’);history.go(-1);/script”;
}
?
註冊界面register.php
form action=”regcheck.php” method=”post”
用戶名:input type=”text” name=”user”/br/
密 碼:input type=”password” name=”pass”/br/
昵 稱:input type=”text” name=”nick”/br/
input type=”submit” name=”sub” value=”註冊”/
/form
註冊處理界面regcheck.php
?php
mysql_connect(‘localhost’,’root’,”);
mysql_select_db(‘test’);
mysql_query(“set names ‘gbk'”);
$nsql=”select username from userinfo where username = ‘$_POST[user]'”;
$result = mysql_query($nsql);
$num = mysql_num_rows($result);
if($num){
echo “scriptalert(‘用戶名已存在註冊失敗’);history.go(-1);/script”;
}else{
$isql = “insert into userinfo values(‘$_POST[user]’,’$_POST[pass]’,’$_POST[nick]’)”;
mysql_query($isql);
echo”scriptalert(‘註冊成功’);history.go(-1);/script”;
}
?
前面加上這句試試。。
if(PHP_VERSION ‘4.1.0’) {$_POST = $HTTP_POST_VARS;}
$userid=$_POST[“userid”];
1、需要建立一個數據表test
id int(10) primary key not null increment
name char(4) not null
pass char(10) not null
age int(2)
city char(5)
2、html頁面自己寫,用表單post傳參
3、.php頁面,處理接收到的參數,於資料庫裡面的用戶名和密碼比對,若果正確,用Js框,輸出歡迎頁面,如果不多返回到登陸頁面
這裡告訴你一個小技巧,很多時候我們都是拿用戶名和密碼一起比對,如果都正確則跳轉。這個地方其實我們需要防止sql注入攻擊,我們可以寫兩條語句,當用戶名正確,我們才執行下一條密碼比對語句,這樣可以有效防止sql的注入攻擊。
我用的是sso(可以百度,原理不說了)登錄模塊,流程是這樣的:
先註冊帳號,註冊成功後user表中有改用會的數據,然後生成一個otp(通行證,用來查詢註冊的用戶信息)和一個signmsg(md5加密驗證字元串),然後在註冊成功後直接用javascript提交的otp和signmsg隱藏表單信息,然後在login模塊用otp查詢到用戶信息 和驗證msgsign的可用性,都通過則登錄成功,否則登入異常。
?php
if($_GET[‘user’] == ‘admin’ $_GET[‘pwd’] == ‘123’)
echo ‘登陸成功’;
?
form action=”” method=”get”/
table border=”0″ cellspacing=”0″ cellpadding=”0″
tr
td class=”fieldKey” width=”30%”用戶名:/td
td class=”fieldValue” width=”100%”input type=”text” name=”user” //td
/tr
trtd height=”10″/td/tr
tr
td class=”fieldKey”密碼:/td
td class=”fieldValue”input type=”password” name=”pwd” //td
/tr
/table
input type=”submit” value=”登陸”/
/form
寫了一個超級簡單的,
你的$mysqli是什麼東西? new mysqli(..);的嗎?
那樣的話query方法在不出錯的情況下返回的是TRUE或 mysqli_result 對象,所以不會出else的結果
應該判斷$result-num_rows來判斷有沒有取到數據
原創文章,作者:SYKAB,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/126229.html