Too simple, but the time is long, remember, waste me half an hour to find information, deep experience good memory than bad pen!! Today, the passport text block affixed to prevent later forget!! Remember, it takes time to find the information you need on the Internet!!!!!!
Passport Pass Integration
First article: The principle of integration
Please note: The possible consequences of an unsuccessful integration-----DZ Forum cannot be logged on and cannot be managed
Workaround:
The first step: to the DZ database table cdb_settings Find the following lines to repair the change to
Setting.gif(4.3 KB)
2006-9-30 13:59
Step two: Remove the DZ installation directory/forumdata/cache/cache_settings.php
Step three: Re-visit the forum
Login and Registration integration process
User submits account password information from login or registration form ==>
Master Program Verification User login or registration, success (registration needs to generate new users) then ==>
Set the main station's own cookie or session ==>
URL delivery returns address forward and encoded user information and other information to dz/api/passport.php
Before you integrate, please read the official Passport technical documents carefully: Http://www.discuz.net/usersguide/advanced_passport.htm copy content to clipboard
Code:
Save this document as login.php
Copy the cryptographic decryption function in the interface technical document first
To keep the code from getting too messy, I copied it to the end of the document.
Suppose your user name in the database table is username, password field is PWD, email field is email
Registration page Implementation method is similar, can be self-realization, doubt add me qq:2666556
$act = (isset ($_get[' act '))? $_get[' act ']: "Login";
if (function_exists ($act)) $act (); else login ();
function Login ()
{
$ERRMSG =usercheck ();
if ($ERRMSG! = "") echo $ERRMSG;
followed by the code that displays your login form, such as
?>
}//end function
function logout ()//Logout
{
$passportkey = "1234567890";//This is replaced by your forum pass Passportkey
$auth =$_cookie[' auth '];
Setcookie ("auth", "", Time ()-3600);
$forward =$_get[' forward '];
if ($forward = = "") $forward = ". /.. /index.php ";//change here to your homepage absolute address or relative address
$verify = MD5 (' logout '. $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 ()
{
$passportkey = "1234567890";//This is replaced by your forum pass Passportkey
=========== Validate Input =====================
if (!isset ($_post[' submit ')) return; The button for the login form needs to have the same name as
$USNM =$_post[' username '];//username the username field in your login form
$pwd =$_post[' password '];//password the password field in your login form
if ($USNM = = "") return "Please enter user name!";
if ($pwd = = "") return "Please enter your password!";
========= 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 "Password error";
Mysql_free_result ($RS);
==============header to bbs=====================
$member = array
(
' Time ' = Time (),
' Username ' = $row ["username"],
' Password ' = $row ["PWD"],
' Email ' and $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 ";
$verify = MD5 (' login '. $auth. $forward. $passportkey);
$auth =rawurlencode ($auth);
$forward =rawurlencode ($forward);
Header ("Location:bbs/api/passport.php?action=login&auth= $auth &forward= $forward &verify= $verify");
}
//=============================================================
============= The following is a copy of the function ============================
function Passport_encrypt ($txt, $key) {
Srand (Double) microtime () * 1000000);
$encrypt _key = MD5 (rand (0, 32000));
$ctr = 0;
$tmp = ";
for ($i = 0; $i < strlen ($txt); $i + +) {
$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
$tmp. = $encrypt _key[$ctr]. ($txt [$i] ^ $encrypt _key[$ctr + +]);
}
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);
}
//=========================================================================
=========================== Copy End ======================================
?>
http://www.bkjia.com/PHPjc/319256.html www.bkjia.com true http://www.bkjia.com/PHPjc/319256.html techarticle too simple, but the time is long, remember, waste me half an hour to find information, deep experience good memory than bad pen!! Today, the passport text block affixed to prevent later forget!! Remember, the net ...