Discuz Passport Pass Integration notes _php tips

Source: Internet
Author: User
Tags auth setcookie strlen
Too simple, but a long time, not remember, wasting my half an hour to find information, profound experience good memory than rotten 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

Chapter One: The principle of integration

Please note: The possible consequences of an unsuccessful consolidation-----DZ Forum cannot log in, cannot manage
The first step: to DZ's database table cdb_settings find the following lines to amend
setting.gif (4.3 KB)
2006-9-30 13:59

Step Two: Remove dz install directory/forumdata/cache/cache_settings.php
Step three: Re-access the forum

Login and registration integration process
User submits account password information from login or registration form ==>
The main station procedure examines the user to log in or registers, succeeds (registers needs to generate new user) then ==>
Set the home station's own cookie or session ==>
URL passes return address forward and encoded user information and other information to dz/api/passport.php

Please read the official Passport technical documentation carefully before consolidating: http://www.discuz.net/usersguide/advanced_passport.htm
Copy Content to Clipboard


This document is saved as a login.php
First, encrypt and decrypt the function copy in the interface technical document
I copied it to the end of the document in order not to mess up the code.
Suppose your user database table user Name field username, password field pwd, email field email
The registration page implementation method is similar, may realize by itself, the question adds 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 showing your login form, such as
<form Action=login.php?act=login method=post>
User name: <input name=username>
Password: <input name=password>
<input name=submit type=submit value= Landing ></form>

}//end function

function logout ()/Log Out
$passportkey = "1234567890"; Here's your forum pass setting Passportkey
$auth =$_cookie[' auth '];
Setcookie ("auth", "" ", Time ()-3600);
$forward =$_get[' forward '];
if ($forward = = "") $forward = ". /.. /index.php "//Here Replace your home page absolute 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"; Here's your forum pass setting Passportkey

=========== Validation Input =====================
if (!isset ($_post[' submit ')) return; The button for the login form needs to have the same name as this
$USNM =$_post[' username '];//username replaced by the username field you landed in the form.
$pwd =$_post[' password '];//password replaced by the password field you landed on your form.
if ($USNM = = "") return "Please enter username!";
if ($pwd = = "") return "Please enter the 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 ' => $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 functions that are copied here ============================
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 ======================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.