/** * 字符转义 * @return string */ function fAddslashes($string) { if (is_array($string)) { foreach ($string as $key => $val) { unset($string[$key]); $string[addslashes($key)] = fAddslashes($val); } } else { $string = addslashes($string); } return $string; }
public function ajaxRegister() { global $_FANWE; $rhash = $_FANWE['request']['rhash']; $agreement = isset($_FANWE['request']['agreement']) ? intval($_FANWE['request']['agreement']) : 0; if ($agreement == 0) { exit('Access Denied'); } $verify = fAddslashes(explode("\t", authcode($_FANWE['cookie']['verify' . $rhash], 'DECODE', $_FANWE['config']['security']['authkey']))); if (empty($rhash) || $rhash != FORM_HASH || empty($verify) || $verify[2] != $rhash || $verify[3] != FORM_HASH) { exit('Access Denied'); } $result = array(); $data = array('checkcode' => strtoupper($_FANWE['request']['checkcode']), 'email' => $_FANWE['request']['email'], 'user_name' => $_FANWE['request']['user_name'], 'password' => $_FANWE['request']['password'], 'confirm_password' => $_FANWE['request']['confirm_password'], 'gender' => intval($_FANWE['request']['gender'])); $vservice = FS('Validate'); $validate = array(array('checkcode', 'equal', lang('user', 'register_checkcode_error'), $verify[0]), array('email', 'required', lang('user', 'register_email_require')), array('email', 'email', lang('user', 'register_email_error')), array('user_name', 'required', lang('user', 'register_user_name_require')), array('user_name', 'range_length', lang('user', 'register_user_name_len'), 2, 20), array('user_name', '/^[\\x{4e00}-\\x{9fa5}a-zA-Z][\\x{4e00}-\\x{9fa5}a-zA-Z0-9]+$/u', lang('user', 'register_user_name_error')), array('password', 'range_length', lang('user', 'register_password_range'), 6, 20), array('confirm_password', 'equal', lang('user', 'confirm_password_error'), $data['password'])); if (!$vservice->validation($validate, $data)) { $result['status'] = 0; $result['msg'] = $vservice->getError(); outputJson($result); } $uservice = FS('User'); if ($uservice->getEmailExists($data['email'])) { $result['status'] = 0; $result['msg'] = lang('user', 'register_email_exist'); outputJson($result); } if ($uservice->getUserNameExists($data['user_name'])) { $result['status'] = 0; $result['msg'] = lang('user', 'register_user_name_exist'); outputJson($result); } //================add by chenfq 2011-10-14 ======================= $user_field = $_FANWE['setting']['integrate_field_id']; $integrate_id = FS("Integrate")->addUser($data['user_name'], $data['password'], $data['email']); if ($integrate_id < 0) { $info = FS("Integrate")->getInfo(); $result['status'] = 0; $result['msg'] = $info; outputJson($result); } //================add by chenfq 2011-10-14======================= $user = array('email' => $data['email'], 'user_name' => $data['user_name'], 'user_name_match' => segmentToUnicode($data['user_name']), 'password' => md5($data['password']), 'status' => 1, 'email_status' => 0, 'avatar_status' => 0, 'gid' => 7, 'invite_id' => FS('User')->getReferrals(), 'reg_time' => TIME_UTC, $user_field => $integrate_id); $uid = FDB::insert('user', $user, true); if ($uid > 0) { $_FANWE['uid'] = $uid; FDB::insert('user_count', array('uid' => $uid)); if ($user['invite_id'] > 0) { FS('User')->insertReferral($uid, $user['invite_id'], $user['user_name']); } FS("User")->updateUserScore($uid, 'user', 'register'); unset($user); $user_profile = array('uid' => $uid, 'gender' => $data['gender']); FDB::insert('user_profile', $user_profile); unset($user_profile); $user_status = array('uid' => $uid, 'reg_ip' => $_FANWE['client_ip'], 'last_ip' => $_FANWE['client_ip'], 'last_time' => TIME_UTC, 'last_activity' => TIME_UTC); FDB::insert('user_status', $user_status); $user = array('uid' => $uid, 'password' => md5($data['password'])); fSetCookie('last_request', authcode(TIME_UTC - 10, 'ENCODE'), TIME_UTC + 816400, 1, true); FS('User')->setSession($user); $syslogin_js = FS("Integrate")->synLogin($integrate_id); //js 需要在前台执行 add by chenfq 2011-10-15 //$result['syslogin_js'] = $integrate_id.';'.$syslogin_js; if (!empty($syslogin_js)) { fSetCookie("dynamic_script", $syslogin_js); } $result['status'] = 1; if (getCookie('redir_url')) { //判断采集图片回调地址,cookie中保持的地址,只使用一次 unset($_FANWE['cookie']['redir_url']); } outputJson($result); } else { $result['status'] = 0; $result['msg'] = lang('user', 'register_error'); outputJson($result); } }
function update() { if ($this->sid !== NULL) { $data = fAddslashes($this->var); if ($this->is_new) { $this->delete(); FDB::insert('sessions', $data, false, false, true); } else { FDB::update('sessions', $data, "sid='{$data['sid']}'"); } fSetCookie('sid', $this->sid, 86400); } }
public function buildUser($uid) { if ($this->is_user) { if ($auth = $this->var['cookie']['auth']) { $auth = fAddslashes(explode("\t", authcode($auth, 'DECODE'))); } list($password, $uid) = empty($auth) || count($auth) < 2 ? array('', '') : $auth; if ($uid) { $user = FS('user')->getUserById($uid); } if (!empty($user) && $user['password'] == $password) { $this->var['user'] = $user; $this->var['authoritys'] = FS('User')->getAuthoritys($uid); FS('User')->init($user); } else { $this->buildGuest(); } } else { $this->buildGuest(); } if (empty($this->var['cookie']['last_visit'])) { $this->var['user']['last_visit'] = TIME_UTC - 3600; fSetCookie('last_visit', TIME_UTC - 3600, 86400 * 30); } else { $this->var['user']['last_visit'] = $this->var['cookie']['last_visit']; } $this->var['uid'] = $this->var['user']['uid']; $this->var['user_name'] = addslashes($this->var['user']['user_name']); $this->var['gid'] = $this->var['user']['gid']; FS('User')->setReferrals(); }
/** * 解码json字符串 * @param string $text 要进行解码字符串 * @param int $type 默认type=0返回obj,type=1返回array * @return mixed */ function decode($text, $type = 0) { if (empty($text)) { return ''; } elseif (!is_string($text)) { return false; } if (function_exists('json_decode')) { return fAddslashes(json_decode(stripslashes($text), $type)); } $this->at = 0; $this->ch = ''; $this->text = strtr(stripslashes($text), array("\r" => '', "\n" => '', "\t" => '', "\\b" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "\v" => '', "\f" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '', "" => '')); $this->next(); $return = $this->val(); $result = empty($type) ? $return : $this->object_to_array($return); return fAddslashes($result); }