太簡單了,但時間長了,記不得,浪費我半小時找資料,深刻體會好記性不如爛筆頭! !今天把passport文擋貼上,防止以後忘記! !記住,網路上找到所需的資料也要耗時的!!!!!!
Passport 通行證整合
第一篇:整合原理setting.gif (4.3 KB)
2006-9-30 13:59
2006-9-30 13:592006-9-30 13:592006-9-30 13:592006-9-30 13:59 🎜>複製內容到剪貼板
<font face="新宋体"> <?php <BR>//該文件儲存為login.php<br>//先將介面技術文件裡的加密解密函數拷貝<br>//為了不讓程式碼太亂,我拷貝到文件的結尾處<br>//假設自己的使用者資料庫表裡使用者名字段為UserName, 密碼欄位為Pwd, Email欄位為Email<br>//登錄頁實作方法差不多,可自行實現,疑問加我QQ:2666556<br>$act=(isset($_GET['act']))?$_GET['act']:"login";<br>if(function_exists($act)) $act();else login(); <br>function login()<br>{ <br> $ErrM=UserCheck();<br> //後面加上顯示你的登陸表單的程式碼如<br>?><br><form action="login.php?act=login" method="post">
<br>使用者名稱:<input name="username"><br>密碼:<input name="password"><br><input name="submit" type="submit" value="登陸">
</form>
<br><?php <BR>}//end function<br>function logout()//登出<br>{<br> $passportkey="1234567890";//這裡換成你論壇通行證設定的passportkey<br> $auth=$_COOKIE['auth'];<br> setcookie("auth),<br> setcookie("auth),<br> ;<br> $forward=$_GET['forward'];<br> if($forward=="")$forward="../../index.php";//這裡換成你的首頁絕對地址或相對地址 $auth=rawurlencode($auth);<br> $forward=rawurlencode($forward) ;<br> header("Location: bbs/api/passport.php?action=logout&auth=$auth&forward=$forward&verify=$verify");<br>}<br>function UserCheck() <br>{ <br> $passportkey="1234567890";//這裡換成你論壇通行證設定的passportkey="1234567890";//這裡換成你論壇通行證設定的passportkey if(!isset($_POST['submit'])) return; // login表單的按鈕需與此同名<br> $usnm=$_POST['username'];//username換成你登陸表單裡的用戶名域 /換成你登陸表單裡的密碼域 if($usnm=="") return "🠭"; //= ========資料庫處理==========================<br> $db=mysql_connect("localhost", "root ", "");<br> mysql_select_db("your_db_name");<br>$sql="Select * from `user` where UserName='".$usnm."' Limit 1"; mysql_query($sql,$db) ;<br> $row = mysql_fetch_array($rs);<br> if(!$row)return "該用戶不存在";<br> if($row["Pwd"] !=md5($pwd))return "密碼錯誤";<br> mysql_free_result($rs); <br> ========== ================ <br> $member = array<br> (<br> ),<br> 'username' => $row[ "UserName"],<br> 'password' => $row["Pwd"],<br> 🎜> );<br> $auth = passport_encrypt(passport_encode ($member), $passportkey);<br> setcookie("auth",$auth,($_POST["Cookie"]? time()+(int)$_POST["Cookie"] :0));<br> $forward=$_POST['forward'];<br> if($forward=="")$forward="../../index.php"; <br> $verify = md5('login '.$auth.$forward.$passportkey);<br> $auth=rawurlencode($auth);<br> $forward=rawurlencode($forward);<br> bbs php?action=login&auth=$auth&forward=$forward&verify=$verify"); =====================================<br>//======== =====以下為拷貝過來的函數============================<br>function passport_encrypt($txt, $key ) {<br> srand((double)microtime() * 1000000);<br> $encrypt_key = md5(rand(0, 32000)); ;<br> $tmp = ''; <br> for($i = 0; $i $tmp . = $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);<br> }<br> return base64_encode(port_key); >function passport_decrypt($txt, $key) {<br> $txt = passport_key(base64_decode($txt), $key);<br> $tmp = '';<i strlen> $tmp .= $txt[$i] ^ $txt[++$i];<br> 1<br>函數passport_key($txt, $encrypt_key) {<br> $encrypt_key = md5($encrypt_key);<br> for($i = 0; $i $ctr = $ctr == strlen($encrypt_key $tmp .= $txt[$i] ^ $encrypt_key[$ ctr++];<br> }<br> return $tmp;<br>}<br>函數passport_encode($array) {<br> for as $key => $val) {<br> $arrayenc[] = $key.'='.urlencode($val);<br> 🎜> //================================================== =============================<br>//================ ============拷貝結束================= ===================== ==<br>?><br><br><br>
<br>
以上就介紹了黑莓passport Discuz Passport通行證整合筆記,包括了黑莓passport方面的內容,希望對PHP教程有興趣的朋友有幫助。 <br>
<br>
<br></i></font>