Home  >  Article  >  Backend Development  >  discuz Passport Pass Integrated Notes_PHP Tutorial

discuz Passport Pass Integrated Notes_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:50:55765browse

太简单了,但时间长了,记不得,浪费我半小时找资料,深刻体会好记性不如烂笔头!!今天把passport文挡贴上,防止以后忘记!!记住,网上找到自己需要的资料也要耗时间的!!!!!!


Passport 通行证 整合

第一篇:整合原理

请注意: 整合不成功可能造成的后果-----dz论坛无法登录,无法管理
解决办法:
第一步: 到dz的数据库表cdb_settings 找到下面这几行修改为
discuz Passport Pass Integrated Notes_PHP Tutorial
setting.gif (4.3 KB)
2006-9-30 13:59

Step 2: Delete the dz installation directory/forumdata/cache/cache_settings.php
Step 3: Re-visit the forum



Log in and register Integration process
The user submits the account and password information from the login or registration form ==> Set the cookie or session of the main website itself ==>
url passes the return address forward and encoded user information and other information to dz/api/passport.php


integration Please read the official passport technical documentation carefully beforehand:
http://www.discuz.net/usersguide/advanced_passport.htm Copy content to clipboard
Code:
//Save this document as login.php//First copy the encryption and decryption function in the interface technical document
/ /In order not to make the code too messy, I copied it to the end of the document
//Assume that the user name field in my user database table is UserName, the password field is Pwd, and the Email field is Email
//Registration page implementation The method is similar and you can implement it yourself. If you have any questions, please send me QQ:2666556

$act=(isset($_GET['act']))?$_GET['act']:"login";
if(function_exists($act)) $act();else login();                                                                                          ="")echo $ErrMsg;                                                                                                                                                                                                                                                                                             🎜>Username:
Password:

< ;?php

}//end function

function logout()//Logout
{
$passportkey="1234567890";//Replace your forum pass here Set passportkey
$auth=$_COOKIE['auth'];
setcookie("auth", "",time() - 3600);
$forward=$_GET['forward'];
If($forward=="")$forward="../../index.php";//Replace here with the absolute address or relative address of your homepage '.$auth.$forward.$passportkey);
$auth=rawurlencode($auth);
$forward=rawurlencode($forward);
header("Location: bbs/api/passport. php?action=logout&auth=$auth&forward=$forward&verify=$verify");
}

function UserCheck()
{                                                                                                                                              ====Verify input======================
if(!isset($_POST['submit'])) return; // login form The button needs to have the same name
$usnm=$_POST['username'];//username is replaced with the username field in your login form                                                                                                                                            Change to the password domain you log in to the form
if ($ usnm == "") Return, please enter the user name! ";
if ($ pwd ==" ") Return.

//==========Database processing==========================
$db =mysql_connect("localhost", "root", "");
mysql_select_db("your_db_name");
$sql="Select * from `user` where UserName='".$usnm."' Limit 1"; ;
$rs = mysql_query($sql,$db) ;
$row = mysql_fetch_array($rs);
if(!$row)return "The user does not exist";
if($row["Pwd"]!=md5($pwd))return "Wrong password";
mysql_free_result($rs);

//========== ====header to bbs======================                                                                                                                                                                                                            ),
                          'username' => $row["UserName"],
                       'email' => $row["Email "]
);
$auth = passport_encrypt(passport_encode($member), $passportkey);
setcookie("auth",$auth,($_POST["Cookie"]? time()+ (int)$_POST["Cookie"] :0));
$forward=$_POST['forward'];
if($forward=="")$forward="../.. /index.php";                                                 $forward=rawurlencode($forward );
header("Location: bbs/api/passport.php?action=login&auth=$auth&forward=$forward&verify=$verify"); /================================================== ===========
//==============The following are the copied functions============== ==============
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5( rand (0, 32000)); 🎜>                                                                                          ]);
}
Return base64_encode(passport_key($tmp, $key));
}

function passport_decrypt($txt, $key) {
$txt = passport_key(base64_decode( $txt), $key);
$tmp = '';
for ($i = 0; $i < strlen($txt); $i++) {
$tmp .= $txt [$i] ^ $txt[++$i];
} }
      return $tmp;
}

function passport_key($txt, $encrypt_key) {
        $encrypt_key = md5($encrypt_key);
        $ctr = 0;
        $tmp = '';
        for($i = 0; $i < strlen($txt); $i++) {
                        $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
                        $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
        }
        return $tmp;
}

function passport_encode($array) {
        $arrayenc = array();
        foreach($array as $key => $val) {
                   $arrayenc[] = $key.'='.urlencode($val);
        }
        return implode('&', $arrayenc);

}
//=========================================================================
//===========================拷贝结束======================================
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319256.htmlTechArticle太简单了,但时间长了,记不得,浪费我半小时找资料,深刻体会好记性不如烂笔头!!今天把passport文挡贴上,防止以后忘记!!记住,网...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn