Register
integer uc_user_register(string username , string password , string email [, integer questionid , string answer])
function parameters
| parameter |
meaning |
| string username |
User Name |
| string password |
Password |
| string email |
E-mail |
| integer questionid |
Security question index |
| string answer |
Security question answer |
| string regip |
Registration IP |
return value
| value |
meaning |
| integer |
> 0: return the user ID, that user registration is successful
-1: the user name is not legitimate
-2: contains words not allowed to register
-3: the user name already exists
-4: Email format is incorrect
-5: Email does not allow registration
-6: The Email is already registered
|
The interface function for the new user registration. User name, password, Email for a user UCenter basic data, after the submission of UCenter will be in accordance with the registered settings and word filtering rules for testing the user name and Email in the format is correct legally, if the correct return registration user ID, otherwise it returns the corresponding error message.
$uid = uc_user_register($_POST['username'], $_POST['password'], $_POST['email']);
if($uid <= 0) {
if($uid == -1) {
echo 'User name not valid';
} elseif($uid == -2) {
echo 'Registration data contains disabled words';
} elseif($uid == -3) {
echo 'User name already exists';
} elseif($uid == -4) {
echo 'Email format is incorrect';
} elseif($uid == -5) {
echo 'This Email does not allowed for registration';
} elseif($uid == -6) {
echo 'This Email is already registered';
} else {
echo 'Undefined error';
}
} else {
echo 'Registered successfully';
}
User Login
array uc_user_login(string username , string password [, bool isuid , bool checkques , integer questionid , string answer])
Function parameters
| parameter |
meaning |
| string username |
User name / User ID |
| string password |
Password |
| bool isuid |
The use of user ID login
1: Use the user ID for login
2: Use E-mail for login
0: (default value) use the username
|
| bool checkques |
Whether to Verify sequrity questions
1: authentication security questions
0: (default value) did not verify the security question
|
| integer questionid |
Security questions index |
| string answer |
Security question answer |
Return value
| value |
meaning |
| array |
integer [0] |
> 0: return the user ID, that user logs on successfully
-1: the user does not exist, or deleted
-2: password wrong
-3: security question wrong
|
| string [1] |
User Name |
| string [2] |
Password |
| string [3] |
Email |
| bool [4] |
user name allready exists |
The interface functions for the user's login authentication, user name and password are correct returns the user UCenter basic data, otherwise it returns the corresponding error message. If the application is an upgrade over, and there are users currently logged on user and the same name, then the returned array [4] will return a value.
list($uid, $username, $password, $email) = uc_user_login($_POST['username'], $_POST['password']);
if($uid > 0) {
echo 'Login successful';
} elseif($uid == -1) {
echo 'User does not exist, or was removed';
} elseif($uid == -2) {
echo 'Password invalid';
} else {
echo 'Undefined error';
}
Access to user data
array uc_get_user(string username [, bool isuid])
Function parameters
| parameter |
meaning |
| string username |
User Name |
| bool isuid |
Whether to use the user ID
1: use the user ID
0: (default value) using the User Name
|
Return value
| value |
meaning |
| array |
integer [0] |
User ID |
| string [1] |
User Name |
| string [2] |
Email |
This interface function is used to obtain from UCenter the user basic data. If the user does not exist, the return value is integer value 0.
if($data = uc_get_user($username)) {
list($uid, $username, $email) = $data;
} else {
echo 'User does not exist';
}
Update user information
integer uc_user_edit(string username , string oldpw , string newpw , string email [, bool ignoreoldpw, integer questionid , string answer])
Function parameters
| parameter |
meaning |
| string username |
User Name |
| string oldpw |
Old Password |
| string newpw |
new password, empty if not changed |
| string email |
Email, empty if not changed |
| bool ignoreoldpw |
It ignores the old password
1: ignore, change the data and do NOT verify the password
0: (default value) do not ignore, for change the data need to verify your password
|
| integer questionid |
Security questions index |
| string answer |
Security question answer |
Return value
| value |
meaning |
| integer |
1: updated successfully
0: did not made any changes
-1: the old password is incorrect
-4: Email format is incorrect
-5: Email does not allowed for registration
-6: The Email is already registered
-7: ddid not made any changes
-8: The user is protected, do not have permission to change
|
This interface function is used to update user information. Update the information required to verify the user's original password is correct, unless specified ignoreoldpw 1. If you only modify the Email does not modify the code that allows newpw empty; the same token, if only to modify the password does not modify the Email, allow email is empty.
$ucresult = uc_user_edit($_POST['username'], $_POST['oldpassword'], $_POST['newpassword'], $_POST['emailnew']);
if($ucresult == -1) {
echo 'Old password is incorrect';
} elseif($ucresult == -4) {
echo 'Email format is incorrect';
} elseif($ucresult == -5) {
echo 'Email does not allowed for registration';
} elseif($ucresult == -6) {
echo 'This Email is already registered';
}
Remove users
integer uc_user_delete(string/array username)
Function parameters
| parameter |
meaning |
| string/array username |
User Name |
Return value
| value |
meaning |
| integer |
1: success
0: fail
|
Remove user avatar
integer uc_user_deleteavatar(string/array username)
Function parameters
| parameter |
meaning |
| string/array username |
User Name |
Synchronization login
string uc_user_synlogin(integer uid)
Function parameters
| parameter |
meaning |
| integer uid |
User ID |
Return value
| value |
meaning |
| string |
HTML code synchronous login |
If the current application set UCenter allow synchronization login, then this interface function will notify the other set the synchronization log on the application log, to return to the HTML output in the page to complete the notification of the other applications. HTML output contains the implementation of remote scripting javascript, please allow this script to run the page to jump after the operation is completed, it may cause can not be successful synchronization log. We should also ensure the correct and effective synchronization log, please ensure that other applications of the Cookie Domain and Cookie Path set correctly.
list($uid, $username, $password, $email) = uc_user_login($_POST['username'], $_POST['password']);
if($uid > 0) {
echo 'Login successful';
echo uc_user_synlogin($uid);
} elseif($uid == -1) {
echo 'User does not exist or removed';
} elseif($uid == -2) {
echo 'Password error';
} else {
echo 'Undefined error';
}
Synchronization logout
string uc_user_synlogout()
return value
| value |
meaning |
| string |
HTML code synchronization exit |
If the current application set UCenter allow synchronization login, then this interface function will notify the other set synchronization logout on the application logout, to return to the HTML output can be completed in the page to inform other applications. HTML output contains the implementation of remote scripting javascript, please allow this script to run the page to jump after the operation is completed, it may cause no synchronization exit logout. While simultaneously out of the registry to ensure correct and effective, please ensure that other applications of the Cookie Domain and Cookie Path set correctly.
Check Email Address
integer uc_user_checkemail(string email)
Function parameters
| parameter |
meaning |
| string email |
Email |
Return value
| value |
meaning |
| integer |
1: success
-4: Email format is incorrect
-5: Email does not allowed for registration
-6: The Email is already registered
|
This interface function is used to check the legitimacy of user input Email.
$ucresult = uc_user_checkemail($_GET['email']);
if($ucresult > 0) {
echo 'Email format is correct';
} elseif($ucresult == -4) {
echo 'Email format is incorrect';
} elseif($ucresult == -5) {
echo 'Email does not allowed for registration';
} elseif($ucresult == -6) {
echo 'This Email is already registered';
}
Check the user name
integer uc_user_checkname(string username)
Function parameters
| parameter |
meaning |
| string username |
User Name |
Return value
| value |
meaning |
| integer |
1: user name is ok
-1: the user name is not legitimate
-2: user name contains words that not allowed for registration
-3: the user name already exists
|
This function is used to check user input interface, the user name of legitimacy.
$ucresult = uc_user_checkname($_GET['email']);
if($ucresult > 0) {
echo 'User name is available';
} elseif($ucresult == -1) {
echo 'User name is not valid';
} elseif($ucresult == -2) {
echo 'User name contains disabled words';
} elseif($ucresult == -3) {
echo 'User name already exists';
}
Add to protected users
integer uc_user_addprotected(string/array username , string admin)
Function parameters
| parameter |
meaning |
| string/array username |
protect the user name |
| string admin |
Administrator |
Return value
| value |
meaning |
| integer |
1: success
-1: fail
|
The interface functions is used for adding protected users.
Delete from protected users
integer uc_user_deleteprotected(string/array username)
Function parameters
| parameter |
meaning |
| string/array username |
protected user name |
Return value
| value |
meaning |
| integer |
1: success
-1: fail
|
This function is used to remove the protected user.
Get a list of protected user names
integer uc_user_getprotected()
Return value
| value |
meaning |
| array |
Protected user data
|
The interface function is used to get a list of protected users.
Merge user. Set the same user name into UCenter
integer uc_user_merge(string/ oldusername , string newusername, integer uid, string password, string email)
Function parameters
| parameter |
meaning |
| string oldusername |
old user name |
| string newusername |
new user name |
| integer uid |
User ID |
| string password |
Password |
| string email |
E-mail |
return value
| value |
meaning |
| integer |
> 0: return the user ID, that user registration is successful
-1: User name is not valid
-2: Contains words not allowed for registration
-3: user name already exists
|
The interface to the user function is used to duplicate names into UCenter.
Handling the same name of user and merged user
If your application when integrated into UCenter contains the old user data, we suggest that you can take the following example of the way to your users into UCenter.
function getmaxuid() {
global $ucdb;
$query = $ucdb->query("SHOW CREATE TABLE ".UC_DBTABLEPRE."members");
$data = $ucdb->fetch_array($query);
$data = $data['Create Table'];
if(preg_match('/AUTO_INCREMENT=(\d+?)[\s|$]/i', $data, $a)) {
return $a[1] - 1;
} else {
return 0;
}
}
$maxuid = getmaxuid();
$query = $db->query("SELECT * FROM {$tablepre}members");
while($data = $db->fetch_array($query)) {
$salt = rand(100000, 999999);
$password = md5($data['password'].$salt);
$data['username'] = addslashes($data['username']);
$lastuid = $data['uid'] += $maxuid;
$queryuc = $ucdb->query("SELECT count(*) FROM ".UC_DBTABLEPRE."members WHERE username='$data[username]'");
$userexist = $ucdb->result($queryuc, 0);
if(!$userexist) {
$ucdb->query("INSERT LOW_PRIORITY INTO ".UC_DBTABLEPRE."members SET uid='$data[uid]', username='$data[username]', password='$password',
email='$data[email]', regip='$data[regip]', regdate='$data[regdate]', salt='$salt'", 'SILENT');
$ucdb->query("INSERT LOW_PRIORITY INTO ".UC_DBTABLEPRE."memberfields SET uid='$data[uid]'",'SILENT');
} else {
$ucdb->query("REPLACE INTO ".UC_DBTABLEPRE."mergemembers SET appid='".UC_APPID."', username='$data[username]'", 'SILENT');
}
}
$ucdb->query("ALTER TABLE ".UC_DBTABLEPRE."members AUTO_INCREMENT=".($lastuid + 1));
The basic process is this way:
First, get the current UCenter the largest user ID value.
Then, read the application its own user table,
reading the user name is repeated in UCenter.
If repeated, the same name of the user name saved to UCenter
the mergemembers table, do not merge the user.
If you do not duplicate, according to the user to merge into the normal way.
When the user inserted into mergemembers form,
the user logged in the application when signed return array [4]
the value will return 1 (
see above on uc_user_login() function Description ).
When logged back to Chong Ming state after the application
of the proposed interpretation of your user name change after the legality of
the treatment, call the interface function.
$uid = uc_user_merge($_GET['username'], $_GET['usernamenew'], $user['uid'], $_GET['password'], $user['email']);
if($uid > 0) {
echo 'User name is available';
} elseif($uid == -1) {
echo 'User name is not valid';
} elseif($uid == -2) {
echo 'Contains words not allowed for register';
} elseif($uid == -3) {
echo 'User name already exists';
}
$db->query("UPDATE {$tablepre}members SET username='$_GET[usernamenew]' WHERE uid='$uid'");
Remove duplicate user name records
uc_user_merge_remove(string username)
Function parameters
| parameter |
meaning |
| string username |
User Name |
This interface function is used to remove duplicate names in the specified user record record, if the application has been processed the same name as the user, can perform this interface function.
access to specified applications with specified users integration
integer uc_user_getcredit(integer appid, integer uid, integer credit)
Function parameters
| parameter |
meaning |
| integer appid |
Application ID
|
| integer uid |
User ID
|
| integer credit |
Number of points
|
Return value
| value |
meaning |
| integer |
Summ of points
|
This interface function is used to specify the application of the specified user access points.