• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP getremoteaddr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中getremoteaddr函数的典型用法代码示例。如果您正苦于以下问题:PHP getremoteaddr函数的具体用法?PHP getremoteaddr怎么用?PHP getremoteaddr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getremoteaddr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_content

 public function get_content()
 {
     global $CFG, $USER, $OUTPUT;
     if (has_capability('block/papercut:view', $this->context)) {
         $this->content = new stdClass();
         $this->content->footer = '';
         $this->content->items = array();
         $this->content->icons = array();
         $serverip = explode('.', $_SERVER['SERVER_ADDR']);
         $internal = address_in_subnet(getremoteaddr(), $serverip[0] . '.' . $serverip[1]);
         $strnobalance = get_string('nobalance', 'block_papercut');
         $image = $OUTPUT->pix_icon('balance_not_available', $strnobalance, 'block_papercut');
         $http = $CFG->block_papercut_https ? 'https://' : 'http://';
         $serverurl = $http . $CFG->block_papercut_server_url . ':' . $CFG->block_papercut_server_port;
         $scriptattrs = array('type' => 'text/javascript');
         $wisgetsattrs = $scriptattrs;
         $widgetsattrs['src'] = $serverurl . '/content/widgets/widgets.js';
         $script1 = "var pcUsername = '{$USER->username}';" . "var pcServerURL = '{$serverurl}'; pcGetUserDetails();";
         $script2 = "pcInitUserEnvironmentalImpactWidget('widgetEnvironment');" . "pcInitUserBalanceWidget('widgetBalance');";
         if ($internal) {
             $this->content->text .= html_writer::tag('script', '', $widgetsattrs);
         }
         $this->content->text .= html_writer::tag('script', $script1, $scriptattrs);
         $this->content->text .= html_writer::tag('div', $image, array('id' => 'widgetBalance'));
         $this->content->text .= html_writer::tag('div', '', array('id' => 'widgetEnvironment'));
         if ($internal) {
             $this->content->text .= html_writer::tag('script', $script2, $scriptattrs);
         }
         return $this->content;
     }
 }
开发者ID:rtsfc,项目名称:moodle-block_papercut,代码行数:31,代码来源:block_papercut.php


示例2: test_ipaddress_access_rule

 public function test_ipaddress_access_rule()
 {
     $quiz = new stdClass();
     $attempt = new stdClass();
     $cm = new stdClass();
     $cm->id = 0;
     // Test the allowed case by getting the user's IP address. However, this
     // does not always work, for example using the mac install package on my laptop.
     $quiz->subnet = getremoteaddr(null);
     if (!empty($quiz->subnet)) {
         $quiz->questions = '';
         $quizobj = new quiz($quiz, $cm, null);
         $rule = new quizaccess_ipaddress($quizobj, 0);
         $this->assertFalse($rule->prevent_access());
         $this->assertFalse($rule->description());
         $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
         $this->assertFalse($rule->is_finished(0, $attempt));
         $this->assertFalse($rule->end_time($attempt));
         $this->assertFalse($rule->time_left_display($attempt, 0));
     }
     $quiz->subnet = '0.0.0.0';
     $quiz->questions = '';
     $quizobj = new quiz($quiz, $cm, null);
     $rule = new quizaccess_ipaddress($quizobj, 0);
     $this->assertNotEmpty($rule->prevent_access());
     $this->assertEmpty($rule->description());
     $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
     $this->assertFalse($rule->is_finished(0, $attempt));
     $this->assertFalse($rule->end_time($attempt));
     $this->assertFalse($rule->time_left_display($attempt, 0));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:rule_test.php


示例3: prevent_access

 public function prevent_access()
 {
     if (address_in_subnet(getremoteaddr(), $this->quiz->subnet)) {
         return false;
     } else {
         return get_string('subnetwrong', 'quizaccess_ipaddress');
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:8,代码来源:rule.php


示例4: definition

 function definition()
 {
     global $COURSE, $USER, $CFG, $DB;
     $mform =& $this->_form;
     if (isset($this->_customdata)) {
         $features = $this->_customdata;
     } else {
         $features = array();
     }
     // course id needs to be passed for auth purposes
     $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('importfile', 'grades'));
     $mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades'));
     $mform->setDefault('feedback', 0);
     // Restrict the possible upload file types.
     if (!empty($features['acceptedtypes'])) {
         $acceptedtypes = $features['acceptedtypes'];
     } else {
         $acceptedtypes = '*';
     }
     // File upload.
     $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
     $mform->disabledIf('userfile', 'url', 'noteq', '');
     $mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"');
     $mform->setType('url', PARAM_URL);
     $mform->disabledIf('url', 'userfile', 'noteq', '');
     $mform->addHelpButton('url', 'fileurl', 'gradeimport_xml');
     if (!empty($CFG->gradepublishing)) {
         $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
         $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
         $keys = $DB->get_records_select('user_private_key', "script='grade/import' AND instance=? AND userid=?", array($COURSE->id, $USER->id));
         if ($keys) {
             foreach ($keys as $key) {
                 $options[$key->value] = $key->value;
                 // TODO: add more details - ip restriction, valid until ??
             }
         }
         $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
         $mform->addHelpButton('key', 'userkey', 'userkey');
         $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'), '<a href="' . $CFG->wwwroot . '/grade/import/keymanager.php?id=' . $COURSE->id . '">' . get_string('keymanager', 'userkey') . '</a>');
         $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size' => 80));
         $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
         $mform->setDefault('iprestriction', getremoteaddr());
         // own IP - just in case somebody does not know what user key is
         $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional' => true));
         $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
         $mform->setDefault('validuntil', time() + 3600 * 24 * 7);
         // only 1 week default duration - just in case somebody does not know what user key is
         $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
         $mform->disabledIf('validuntil', 'key', 'noteq', 1);
         $mform->disabledIf('iprestriction', 'url', 'eq', '');
         $mform->disabledIf('validuntil', 'url', 'eq', '');
         $mform->disabledIf('key', 'url', 'eq', '');
     }
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:57,代码来源:grade_import_form.php


示例5: plaintext_is_ok

 function plaintext_is_ok()
 {
     global $CFG;
     $trusted_hosts = explode(',', get_config('mnet', 'mnet_trusted_hosts'));
     foreach ($trusted_hosts as $host) {
         if (address_in_subnet(getremoteaddr(), $host)) {
             return true;
         }
     }
     return false;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:11,代码来源:remote_client.php


示例6: sso_user_login

function sso_user_login($username, $password)
{
    global $CFG, $SESSION;
    include $CFG->libdir . '/snoopy/Snoopy.class.inc';
    if (empty($CFG->hivehost)) {
        return false;
        // Hive config variables not configured yet
    }
    /// Set up Snoopy
    $snoopy = new Snoopy();
    $submit_url = $CFG->hiveprotocol . '://' . $CFG->hivehost . ':' . $CFG->hiveport . '' . $CFG->hivepath;
    $submit_vars['HIVE_UNAME'] = $username;
    $submit_vars['HIVE_UPASS'] = $password;
    $submit_vars['HIVE_ENDUSER'] = $username;
    $submit_vars['HIVE_REQ'] = '2112';
    $submit_vars['HIVE_REF'] = 'hin:hive@API Login 3';
    $submit_vars['HIVE_RET'] = 'ORG';
    $submit_vars['HIVE_REM'] = '';
    $submit_vars['HIVE_PROD'] = '0';
    $submit_vars['HIVE_USERIP'] = getremoteaddr();
    /// We use POST to call Hive with a bit more security
    $snoopy->submit($submit_url, $submit_vars);
    /// Extract HIVE_SESSION from headers
    foreach ($snoopy->headers as $header) {
        if (strpos($header, 'HIVE_SESSION=') !== false) {
            $header = explode('HIVE_SESSION=', $header);
            if (count($header) > 1) {
                $cookie = explode(';', $header[1]);
                $cookie = $cookie[0];
                $SESSION->HIVE_SESSION = $cookie;
                return true;
            }
        }
    }
    /// Try again with the guest username and password
    $submit_vars['HIVE_UNAME'] = $CFG->hiveusername;
    $submit_vars['HIVE_UPASS'] = $CFG->hivepassword;
    $submit_vars['HIVE_ENDUSER'] = $CFG->hiveusername;
    $snoopy->submit($submit_url, $submit_vars);
    foreach ($snoopy->headers as $header) {
        if (strpos($header, 'HIVE_SESSION=') !== false) {
            $header = explode('HIVE_SESSION=', $header);
            if (count($header) > 1) {
                $cookie = explode(';', $header[1]);
                $cookie = $cookie[0];
                $SESSION->HIVE_SESSION = $cookie;
                return true;
            }
        }
    }
    return false;
    // No cookie found
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:53,代码来源:lib.php


示例7: initial_checks

 static function initial_checks($id, $password)
 {
     $vpl = new mod_vpl($id);
     //No context validation (session is OK)
     //self::validate_context($vpl->get_context());
     if (!$vpl->pass_network_check()) {
         throw new Exception(get_string('opnotallowfromclient', VPL) . ' ' . getremoteaddr());
     }
     if (!$vpl->pass_password_check($password)) {
         throw new Exception(get_string('requiredpassword', VPL));
     }
     return $vpl;
 }
开发者ID:go38,项目名称:moodle-mod_vpl,代码行数:13,代码来源:externallib.php


示例8: find_lms_user

function find_lms_user($installid, $username, $signature, $confirmaction = null, $firstname = null, $lastname = null, $email = null)
{
    global $CFG;
    // find this host from the installid
    if (empty($CFG->lmshosts) || !is_array($CFG->lmshosts) || !array_key_exists($installid, $CFG->lmshosts)) {
        return LMS_NO_SUCH_HOST;
    }
    $host = $CFG->lmshosts[$installid];
    // validate our md5 hash
    if ($confirmaction == 'signupconfirmation') {
        $stringtohash = $installid . '|' . $username . '|' . $firstname . '|' . $lastname . '|' . $email . '|' . $host['token'];
    } else {
        $stringtohash = $installid . '|' . $username . '|' . $host['token'];
        // firstname, lastname and email cannot be relied upon not to change
        // so we only want to add them to the hash on signup, not for auth or anything else.
    }
    $checksig = md5($stringtohash);
    if ($checksig != $signature) {
        return LMS_INVALID_HASH;
    }
    // if we have an ip address, check it.
    if (array_key_exists('networkaddress', $host) && empty($confirmaction)) {
        if (!address_in_subnet(getremoteaddr(), $host['networkaddress'])) {
            return LMS_INVALID_NETWORK;
        }
    }
    if (!empty($confirmaction) && !empty($host['confirmurl'])) {
        $client = new Snoopy();
        $client->agent = LMS_SNOOPY_USER_AGENT;
        $client->read_timeout = 5;
        $client->use_gzip = true;
        $postdata = array('action' => $confirmaction, 'username' => $username, 'signature' => $signature);
        @$client->submit($host['confirmurl'], $postdata);
        if ($client->results != 'OK') {
            return clean_param($client->results, PARAM_CLEAN);
        }
    }
    // find our user (we only want to check username and installid, the others could potentially change..
    if (!($user = get_record_sql('SELECT u.* FROM ' . $CFG->prefix . 'users u 
                        JOIN ' . $CFG->prefix . 'users_alias ua ON ua.user_id = u.ident
                        WHERE ua.installid = ? AND ua.username = ?', array($installid, $username)))) {
        return LMS_NO_SUCH_USER;
    }
    return $user;
}
开发者ID:BackupTheBerlios,项目名称:tulipan-svn,代码行数:45,代码来源:lmslib.php


示例9: loginpage_hook

 /**
  * Provides a hook into the login page.
  *
  * @param object &$frm Form object.
  * @param object &$user User object.
  */
 public function loginpage_hook(&$frm, &$user)
 {
     global $DB;
     if (empty($frm)) {
         $frm = data_submitted();
     }
     if (empty($frm)) {
         return true;
     }
     $autoappend = get_config('auth_oidc', 'autoappend');
     if (empty($autoappend)) {
         // If we're not doing autoappend, just let things flow naturally.
         return true;
     }
     $username = $frm->username;
     $password = $frm->password;
     $auth = 'oidc';
     $existinguser = $DB->get_record('user', ['username' => $username]);
     if (!empty($existinguser)) {
         // We don't want to prevent access to existing accounts.
         return true;
     }
     $username .= $autoappend;
     $success = $this->user_login($username, $password);
     if ($success !== true) {
         // No o365 user, continue normally.
         return false;
     }
     $existinguser = $DB->get_record('user', ['username' => $username]);
     if (!empty($existinguser)) {
         $user = $existinguser;
         return true;
     }
     // The user is authenticated but user creation may be disabled.
     if (!empty($CFG->authpreventaccountcreation)) {
         $failurereason = AUTH_LOGIN_UNAUTHORISED;
         // Trigger login failed event.
         $event = \core\event\user_login_failed::create(array('other' => array('username' => $username, 'reason' => $failurereason)));
         $event->trigger();
         error_log('[client ' . getremoteaddr() . "]  {$CFG->wwwroot}  Unknown user, can not create new accounts:  {$username}  " . $_SERVER['HTTP_USER_AGENT']);
         return false;
     }
     $user = create_user_record($username, $password, $auth);
     return true;
 }
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:51,代码来源:rocreds.php


示例10: definition

 function definition()
 {
     global $COURSE, $USER, $CFG;
     $mform =& $this->_form;
     $this->set_upload_manager(new upload_manager('userfile', false, false, null, false, 0, true, true, false));
     // course id needs to be passed for auth purposes
     $mform->addElement('hidden', 'id', optional_param('id'));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('importfile', 'grades'));
     $mform->disabledIf('url', 'userfile', 'noteq', '');
     $mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades'));
     $mform->setDefault('feedback', 0);
     // file upload
     $mform->addElement('file', 'userfile', get_string('file'));
     $mform->setType('userfile', PARAM_FILE);
     $mform->disabledIf('userfile', 'url', 'noteq', '');
     $mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"');
     if (!empty($CFG->gradepublishing)) {
         $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
         $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
         if ($keys = get_records_select('user_private_key', "script='grade/import' AND instance={$COURSE->id} AND userid={$USER->id}")) {
             foreach ($keys as $key) {
                 $options[$key->value] = $key->value;
                 // TODO: add more details - ip restriction, valid until ??
             }
         }
         $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
         $mform->setHelpButton('key', array(false, get_string('userkey', 'userkey'), false, true, false, get_string("userkeyhelp", 'grades')));
         $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'), '<a href="' . $CFG->wwwroot . '/grade/import/keymanager.php?id=' . $COURSE->id . '">' . get_string('keymanager', 'userkey') . '</a>');
         $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size' => 80));
         $mform->setHelpButton('iprestriction', array(false, get_string('keyiprestriction', 'userkey'), false, true, false, get_string("keyiprestrictionhelp", 'userkey')));
         $mform->setDefault('iprestriction', getremoteaddr());
         // own IP - just in case somebody does not know what user key is
         $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional' => true));
         $mform->setHelpButton('validuntil', array(false, get_string('keyvaliduntil', 'userkey'), false, true, false, get_string("keyvaliduntilhelp", 'userkey')));
         $mform->setDefault('validuntil', time() + 3600 * 24 * 7);
         // only 1 week default duration - just in case somebody does not know what user key is
         $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
         $mform->disabledIf('validuntil', 'key', 'noteq', 1);
         $mform->disabledIf('iprestriction', 'url', 'eq', '');
         $mform->disabledIf('validuntil', 'url', 'eq', '');
         $mform->disabledIf('key', 'url', 'eq', '');
     }
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:45,代码来源:grade_import_form.php


示例11: isValid

 /**
  * See if the request has the proper remote address
  *
  * @param  Zend_Controller_Request_Http $request The request to check
  * @return boolean
  */
 public function isValid($request)
 {
     if (!empty($this->_ipAddresses)) {
         $remoteaddr = getremoteaddr();
         // Check for localhost IPv6
         if (empty($remoteaddr) and $request->getServer('REMOTE_ADDR') == '::1') {
             $remoteaddr = '127.0.0.1';
         }
         // Can get get the remote address ?
         if (empty($remoteaddr)) {
             $this->_setValue($request->getServer('REMOTE_ADDR'));
             $this->_error(self::NOT_FOUND);
             return false;
         }
         // Address valid ?
         if (!address_in_subnet($remoteaddr, $this->_ipAddresses)) {
             $this->_setValue($remoteaddr);
             $this->_error(self::NOT_VALID);
             return false;
         }
     }
     return true;
 }
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:29,代码来源:ip.php


示例12: magic_get_requestip

 /**
  * Returns request IP address.
  *
  * @return string IP address or null if unknown
  */
 protected function magic_get_requestip()
 {
     return getremoteaddr(null);
 }
开发者ID:fliphess,项目名称:moodle,代码行数:9,代码来源:pagelib.php


示例13: echeck_submit

 /**
  * The user submitted echeck form.
  *
  * @param object $form Form parameters
  * @param object $course Course info
  * @access private
  */
 function echeck_submit($form, $course)
 {
     global $CFG, $USER, $SESSION;
     require_once 'authorizenetlib.php';
     prevent_double_paid($course);
     $useripno = getremoteaddr();
     $curcost = get_course_cost($course);
     $isbusinesschecking = $form->acctype == 'BUSINESSCHECKING';
     // NEW ECHECK ORDER
     $timenow = time();
     $order = new stdClass();
     $order->paymentmethod = AN_METHOD_ECHECK;
     $order->refundinfo = $isbusinesschecking ? 1 : 0;
     $order->ccname = $form->firstname . ' ' . $form->lastname;
     $order->courseid = $course->id;
     $order->userid = $USER->id;
     $order->status = AN_STATUS_NONE;
     // it will be changed...
     $order->settletime = 0;
     // cron changes this.
     $order->transid = 0;
     // Transaction Id
     $order->timecreated = $timenow;
     $order->amount = $curcost['cost'];
     $order->currency = $curcost['currency'];
     $order->id = insert_record("enrol_authorize", $order);
     if (!$order->id) {
         email_to_admin("Error while trying to insert new data", $order);
         return "Insert record error. Admin has been notified!";
     }
     $extra = new stdClass();
     $extra->x_bank_aba_code = $form->abacode;
     $extra->x_bank_acct_num = $form->accnum;
     $extra->x_bank_acct_type = $form->acctype;
     $extra->x_echeck_type = $isbusinesschecking ? 'CCD' : 'WEB';
     $extra->x_bank_name = $form->bankname;
     $extra->x_currency_code = $curcost['currency'];
     $extra->x_amount = $curcost['cost'];
     $extra->x_first_name = $form->firstname;
     $extra->x_last_name = $form->lastname;
     $extra->x_country = $USER->country;
     $extra->x_address = $USER->address;
     $extra->x_city = $USER->city;
     $extra->x_state = '';
     $extra->x_zip = '';
     $extra->x_invoice_num = $order->id;
     $extra->x_description = $course->shortname;
     $extra->x_cust_id = $USER->id;
     $extra->x_email = $USER->email;
     $extra->x_customer_ip = $useripno;
     $extra->x_email_customer = empty($CFG->enrol_mailstudents) ? 'FALSE' : 'TRUE';
     $extra->x_phone = '';
     $extra->x_fax = '';
     $message = '';
     if (AN_REVIEW != authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) {
         email_to_admin($message, $order);
         return $message;
     }
     $SESSION->ccpaid = 1;
     // security check: don't duplicate payment
     redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
 }
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:69,代码来源:enrol.php


示例14: ewiki_author

function ewiki_author($defstr = "")
{
    $author = @$GLOBALS["ewiki_author"];
    $ip = getremoteaddr() or $ip = "127.0.0.0";
    $port = $_SERVER["REMOTE_PORT"] or $port = "null";
    $hostname = $ip;
    $remote = ($ip != $hostname ? $hostname . " " : "") . $ip . ":" . $port;
    empty($author) && (($author = $defstr) || ($author = $_SERVER["HTTP_FROM"]) || ($author = $_SERVER["PHP_AUTH_USER"]));
    empty($author) && ($author = $remote) || ($author = addslashes($author) . " (" . $remote . ")");
    return $author;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:11,代码来源:ewiki.php


示例15: remoteip_in_list

/**
 * Is current ip in give list?
 *
 * @param string $list
 * @return bool
 */
function remoteip_in_list($list)
{
    $inlist = false;
    $clientip = getremoteaddr(null);
    if (!$clientip) {
        // Ensure access on cli.
        return true;
    }
    $list = explode("\n", $list);
    foreach ($list as $subnet) {
        $subnet = trim($subnet);
        if (address_in_subnet($clientip, $subnet)) {
            $inlist = true;
            break;
        }
    }
    return $inlist;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:24,代码来源:moodlelib.php


示例16: check_entry

 /**
 * The other half to print_entry, this checks the form data
 *
 * This function checks that the user has completed the task on the
 * enrolment entry page and then enrolls them.
 *
 * @param    form    the form data submitted, as an object
 * @param    course  the current course, as an object
 */
 function check_entry($form, $course)
 {
     global $CFG, $USER, $SESSION, $THEME;
     if (empty($form->password)) {
         $form->password = '';
     }
     if (empty($course->password)) {
         // do not allow entry when no course password set
         // automatic login when manual primary, no login when secondary at all!!
         error('illegal enrolment attempted');
     }
     $groupid = $this->check_group_entry($course->id, $form->password);
     if (stripslashes($form->password) == $course->password or $groupid !== false) {
         if (isguestuser()) {
             // only real user guest, do not use this for users with guest role
             $USER->enrolkey[$course->id] = true;
             add_to_log($course->id, 'course', 'guest', 'view.php?id=' . $course->id, getremoteaddr());
         } else {
             /// Update or add new enrolment
             if (enrol_into_course($course, $USER, 'manual')) {
                 // force a refresh of mycourses
                 unset($USER->mycourses);
                 if ($groupid !== false) {
                     if (!groups_add_member($groupid, $USER->id)) {
                         print_error('couldnotassigngroup');
                     }
                 }
             } else {
                 print_error('couldnotassignrole');
             }
         }
         if ($SESSION->wantsurl) {
             $destination = $SESSION->wantsurl;
             unset($SESSION->wantsurl);
         } else {
             $destination = "{$CFG->wwwroot}/course/view.php?id={$course->id}";
         }
         redirect($destination);
     } else {
         if (!isset($CFG->enrol_manual_showhint) or $CFG->enrol_manual_showhint) {
             $this->errormsg = get_string('enrolmentkeyhint', '', substr($course->password, 0, 1));
         } else {
             $this->errormsg = get_string('enrolmentkeyerror', 'enrol_manual');
         }
     }
 }
开发者ID:kai707,项目名称:ITSA-backup,代码行数:55,代码来源:enrol.php


示例17: redirect

        if (!$sessionverify) {
            $SESSION->sessionverify = 1;
            redirect("index.php?sessionstarted=1&sessionverify=1&lang={$CFG->lang}");
        } else {
            if (empty($SESSION->sessionverify)) {
                print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang={$CFG->lang}");
            }
            unset($SESSION->sessionverify);
        }
    }
    // at this stage there can be only one admin unless more were added by install - users may change username, so do not rely on that
    $adminids = explode(',', $CFG->siteadmins);
    $adminuser = get_complete_user_data('id', reset($adminids));
    if ($adminuser->password === 'adminsetuppending') {
        // prevent installation hijacking
        if ($adminuser->lastip !== getremoteaddr()) {
            print_error('installhijacked', 'admin');
        }
        // login user and let him set password and admin details
        $adminuser->newadminuser = 1;
        complete_user_login($adminuser);
        redirect("{$CFG->wwwroot}/user/editadvanced.php?id={$adminuser->id}");
        // Edit thyself
    } else {
        unset_config('adminsetuppending');
    }
} else {
    // just make sure upgrade logging is properly terminated
    upgrade_finished('upgradesettings.php');
}
// Turn xmlstrictheaders back on now.
开发者ID:numbas,项目名称:moodle,代码行数:31,代码来源:index.php


示例18: xmldb_main_install


//.........这里部分代码省略.........
    $guest = new stdClass();
    $guest->auth = 'manual';
    $guest->username = 'guest';
    $guest->password = hash_internal_user_password('guest');
    $guest->firstname = get_string('guestuser');
    $guest->lastname = ' ';
    $guest->email = 'root@localhost';
    $guest->description = get_string('guestuserinfo');
    $guest->mnethostid = $CFG->mnet_localhost_id;
    $guest->confirmed = 1;
    $guest->lang = $CFG->lang;
    $guest->timemodified = time();
    $guest->id = $DB->insert_record('user', $guest);
    if ($guest->id != 1) {
        echo $OUTPUT->notification('Unexpected id generated for the Guest account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
    }
    // Store guest id
    set_config('siteguest', $guest->id);
    // Make sure user context exists
    context_user::instance($guest->id);
    // Now create admin user
    $admin = new stdClass();
    $admin->auth = 'manual';
    $admin->firstname = get_string('admin');
    $admin->lastname = get_string('user');
    $admin->username = 'admin';
    $admin->password = 'adminsetuppending';
    $admin->email = '';
    $admin->confirmed = 1;
    $admin->mnethostid = $CFG->mnet_localhost_id;
    $admin->lang = $CFG->lang;
    $admin->maildisplay = 1;
    $admin->timemodified = time();
    $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr();
    // installation hijacking prevention
    $admin->id = $DB->insert_record('user', $admin);
    if ($admin->id != 2) {
        echo $OUTPUT->notification('Unexpected id generated for the Admin account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
    }
    if ($admin->id != $guest->id + 1) {
        echo $OUTPUT->notification('Nonconsecutive id generated for the Admin account. Your database configuration or clustering setup may not be fully supported.', 'notifyproblem');
    }
    // Store list of admins
    set_config('siteadmins', $admin->id);
    // Make sure user context exists
    context_user::instance($admin->id);
    // Install the roles system.
    $managerrole = create_role('', 'manager', '', 'manager');
    $coursecreatorrole = create_role('', 'coursecreator', '', 'coursecreator');
    $editteacherrole = create_role('', 'editingteacher', '', 'editingteacher');
    $noneditteacherrole = create_role('', 'teacher', '', 'teacher');
    $studentrole = create_role('', 'student', '', 'student');
    $guestrole = create_role('', 'guest', '', 'guest');
    $userrole = create_role('', 'user', '', 'user');
    $frontpagerole = create_role('', 'frontpage', '', 'frontpage');
    // Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
    update_capabilities('moodle');
    // Default allow role matrices.
    foreach ($DB->get_records('role') as $role) {
        foreach (array('assign', 'override', 'switch') as $type) {
            $function = 'allow_' . $type;
            $allows = get_default_role_archetype_allows($type, $role->archetype);
            foreach ($allows as $allowid) {
                $function($role->id, $allowid);
            }
        }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:67,代码来源:install.php


示例19: url_get_encrypted_parameter

/**
 * BC internal function
 * @param object $url
 * @param object $config
 * @return string
 */
function url_get_encrypted_parameter($url, $config)
{
    global $CFG;
    if (file_exists("{$CFG->dirroot}/local/externserverfile.php")) {
        require_once "{$CFG->dirroot}/local/externserverfile.php";
        if (function_exists('extern_server_file')) {
            return extern_server_file($url, $config);
        }
    }
    return md5(getremoteaddr() . $config->secretphrase);
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:17,代码来源:locallib.php


示例20: chat_login_user

/**
 * login if not already logged in
 *
 * @global object
 * @global object
 * @param int $chatid
 * @param string $version
 * @param int $groupid
 * @param object $course
 * @return bool|int Returns the chat users sid or false
 */
function chat_login_user($chatid, $version, $groupid, $course)
{
    global $USER, $DB;
    if ($version != 'sockets' and $chatuser = $DB->get_record('chat_users', array('chatid' => $chatid, 'userid' => $USER->id, 'groupid' => $groupid))) {
        // This will update logged user information.
        $chatuser->version = $version;
        $chatuser->ip = $USER->lastip;
        $chatuser->lastping = time();
        $chatuser->lang = current_language();
        // Sometimes $USER->lastip is not setup properly during login.
        // Update with current value if possible or provide a dummy value for the db.
        if (empty($chatuser->ip)) {
            $chatuser->ip = getremoteaddr();
        }
        if ($chatuser->course != $course->id or $chatuser->userid != $USER->id) {
            return false;
        }
        $DB->update_record('chat_users', $chatuser);
    } else {
        $chatuser = new stdClass();
        $chatuser->chatid = $chatid;
        $chatuser->userid = $USER->id;
        $chatuser->groupid = $groupid;
        $chatuser->version = $version;
        $chatuser->ip = $USER->lastip;
        $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
        $chatuser->sid = random_string(32);
        $chatuser->course = $course->id;
        // Caching - needed for current_language too.
        $chatuser->lang = current_language();
        // Caching - to resource intensive to find out later.
        // Sometimes $USER->lastip is not setup properly during login.
        // Update with current value if possible or provide a dummy value for the db.
        if (empty($chatuser->ip)) {
            $chatuser->ip = getremoteaddr();
        }
        $DB->insert_record('chat_users', $chatuser);
        if ($version == 'sockets') {
            // Do not send 'enter' message, chatd will do it.
        } else {
            chat_send_chatmessage($chatuser, 'enter', true);
        }
    }
    return $chatuser->sid;
}
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:56,代码来源:lib.php



注:本文中的getremoteaddr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP getremotefile函数代码示例发布时间:2022-05-15
下一篇:
PHP getrefnum函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap