当前位置: 首页>>代码示例>>PHP>>正文


PHP getremoteaddr函数代码示例

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


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


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