本文整理汇总了PHP中CHttpRequest::getUserHostAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP CHttpRequest::getUserHostAddress方法的具体用法?PHP CHttpRequest::getUserHostAddress怎么用?PHP CHttpRequest::getUserHostAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHttpRequest
的用法示例。
在下文中一共展示了CHttpRequest::getUserHostAddress方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getIP
protected function _getIP($ip = null)
{
if ($ip === null) {
$ip = CHttpRequest::getUserHostAddress();
}
return $ip;
}
示例2: getUserHostAddress
public function getUserHostAddress()
{
$headers = apache_request_headers();
if (!$this->useReverseProxyHeaders || !isset($headers['X-Forwarded-For'])) {
return parent::getUserHostAddress();
}
return $headers['X-Forwarded-For'];
}
示例3: getUserHostAddress
/**
* Переделываем функцию проверки ip,
* так как на некоторых серверах ip храниться не в $_SERVER['REMOTE_ADDR'] a в $_SERVER['HTTP_X_FORWARDED_FOR']
* @return [type] [description]
*/
public function getUserHostAddress()
{
$ip = parent::getUserHostAddress();
if ($ip == '127.0.0.1') {
$newip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : false;
$ip = $newip && $newip != '127.0.0.1' ? $newip : $ip;
}
return $ip;
}
示例4: login
public function login(LoginForm $form, IWebUser $user, CHttpRequest $request = null)
{
if ($form->hasErrors()) {
return false;
}
$identity = new UserIdentity($form->email, $form->password);
$duration = 0;
//if ($form->remember_me) {
$sessionTimeInWeeks = (int) Yii::app()->getModule('user')->sessionLifeTime;
$duration = $sessionTimeInWeeks * 24 * 60 * 60;
//}
if ($identity->authenticate()) {
$user->login($identity, $duration);
Yii::log(Yii::t('UserModule.user', 'User with {email} was logined with IP-address {ip}!', array('{email}' => $form->email, '{ip}' => $request->getUserHostAddress())), CLogger::LEVEL_INFO, UserModule::$logCategory);
return true;
}
Yii::log(Yii::t('UserModule.user', 'Authorization error with IP-address {ip}! email => {email}, Password => {password}!', array('{email}' => $form->email, '{password}' => $form->password, '{ip}' => $request->getUserHostAddress())), CLogger::LEVEL_ERROR, UserModule::$logCategory);
return false;
}
示例5: login
/**
* @param LoginForm $form
* @param IWebUser $user
* @param CHttpRequest|null $request
* @return bool
*/
public function login(LoginForm $form, IWebUser $user, CHttpRequest $request = null)
{
if (false === $form->validate()) {
Yii::app()->eventManager->fire(UserEvents::FAILURE_LOGIN, new UserLoginEvent($form, $user));
return false;
}
$identity = new UserIdentity($form->email, $form->password);
$duration = 0;
if ($form->remember_me) {
$sessionTimeInWeeks = (int) Yii::app()->getModule('user')->sessionLifeTime;
$duration = $sessionTimeInWeeks * 24 * 60 * 60;
}
if ($identity->authenticate()) {
Yii::app()->eventManager->fire(UserEvents::BEFORE_LOGIN, new UserLoginEvent($form, $user, $identity));
$user->login($identity, $duration);
Yii::log(Yii::t('UserModule.user', 'User with {email} was logined with IP-address {ip}!', ['{email}' => $form->email, '{ip}' => $request->getUserHostAddress()]), CLogger::LEVEL_INFO, UserModule::$logCategory);
Yii::app()->eventManager->fire(UserEvents::SUCCESS_LOGIN, new UserLoginEvent($form, $user, $identity));
return true;
}
Yii::app()->eventManager->fire(UserEvents::FAILURE_LOGIN, new UserLoginEvent($form, $user, $identity));
Yii::log(Yii::t('UserModule.user', 'Authorization error with IP-address {ip}! email => {email}, Password => {password}!', ['{email}' => $form->email, '{password}' => $form->password, '{ip}' => $request->getUserHostAddress()]), CLogger::LEVEL_ERROR, UserModule::$logCategory);
return false;
}
示例6: beforeAction
/**
* Cek Akses User dengan CDbAuthManager
* @param type $action
* @return boolean
* @throws CHttpException
*/
protected function beforeAction($action)
{
if ($this->allowIp(CHttpRequest::getUserHostAddress())) {
$superUser = Yii::app()->authManager->getAuthAssignment(Yii::app()->params['superuser'], Yii::app()->user->id) === null ? FALSE : TRUE;
if ($superUser) {
return true;
} else {
if (Yii::app()->user->checkAccess(Yii::app()->controller->id . '.' . Yii::app()->controller->action->id)) {
return true;
} else {
throw new CHttpException(403, 'Akses ditolak - Anda tidak memiliki izin untuk mengakses halaman ini!');
}
}
} else {
throw new CHttpException(403, 'Akses ditolak - Anda tidak memiliki izin untuk mengakses halaman ini!');
}
}
示例7: __
/**
* Logs current Request-Response using Yii::log
* @param string $request
* @param string $response
* @param string $apiMethod
*/
public static function __($request, $response, $apiMethod = null)
{
$controller = Yii::app()->controller;
$response = Response::get();
$status = $response[$controller::$configuration['statusKey']];
if ($status == $controller::$configuration['statusError']) {
$level = 'error';
} else {
$level = 'info';
}
if (!$apiMethod) {
$apiMethod = self::$apiMethod;
}
$http = new CHttpRequest();
$ip = $http->getUserHostAddress();
Yii::log('Request: ' . $request . ' ' . 'Response: ' . $response . ' ' . 'API Method: ' . $apiMethod . ' ' . 'API Version: ' . self::$apiVersion . ' ' . 'IP: ' . $ip . ' ' . 'Status: ' . $status . ' ', $level, 'webervice');
}
示例8: actionLogin
/**
* Displays the login page
*/
public function actionLogin()
{
if (!$this->allowIp(CHttpRequest::getUserHostAddress())) {
throw new CHttpException(403, 'Akses ditolak - Anda tidak memiliki izin untuk mengakses halaman ini!');
}
$model = new LoginForm();
// if it is ajax validation request
/*
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
// collect user input data
if (isset($_POST['LoginForm'])) {
$model->attributes = $_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if ($model->validate() && $model->login()) {
$this->redirect(Yii::app()->user->returnUrl);
}
}
// display the login form
$this->render('login', array('model' => $model));
}
示例9: actionPaypalPayment
public function actionPaypalPayment()
{
$customer_model = new Customer();
$commande_model = new Commande();
$customer_model->attributes = Yii::app()->user->getState('Customer');
$commande_model->attributes = Yii::app()->user->getState('Commande');
if (sizeof($customer_model->search()->getData()) == 0) {
$customer_model->bilsignupip = CHttpRequest::getUserHostAddress();
$customer_model->save();
$commande_model->bilkey = $customer_model->bilkey;
$commande_model->comdebut = date("Y-m-d");
$commande_model->save();
} else {
$customerTemp = $customer_model->search()->getData();
$customer_model->bilkey = $customerTemp[0]->attributes['bilkey'];
}
if (isset($_POST['payment_status'])) {
if ($_POST['payment_status'] == "Completed" || $_POST['payment_status'] == "Pending") {
$city = Goodcity::model()->findByPk($_POST['item_number']);
$this->sendEmailConfirmation($customer_model, $city, $commande_model, $_POST['txn_id'], $this->getInvoiceTotals($customer_model, $commande_model));
$this->render('application/2-orderform', array('goodcity' => $city, 'thanks' => true, 'payment_type' => "paypal", 'payment_method' => "email", 'order_totals' => $this->getInvoiceTotals($customer_model, $commande_model), 'customer_model' => $customer_model, 'commande_model' => $commande_model, 'auth_code' => $_POST['txn_id']));
} else {
$this->redirect(array('user/order', 'transactionError' => true));
}
} else {
$city = Goodcity::model()->findByPk($commande_model['comgoodcitykey']);
$this->redirect(array('user/signup', 'city' => $commande_model['comgoodcitykey']));
}
}
示例10: UpdateLastLoginOnResetPassword
public function UpdateLastLoginOnResetPassword($user_id)
{
$user_ip = CHttpRequest::getUserHostAddress();
$log_model = new Admin_ajax();
// $log_model->addLog("Update", 'su_user', $user_id, 'Performed Update Operation');
$update_last_login = Yii::app()->db->createCommand('UPDATE users SET user_last_login_time = "' . NULL . '", user_ip_address = "' . $user_ip . '" WHERE user_id = "' . $user_id . '" ')->query();
return true;
}
示例11: writeSession
public function writeSession($id, $data)
{
try {
$expire = time() + $this->getTimeout();
$db = $this->getDbConnection();
if ($db->getDriverName() == 'sqlsrv' || $db->getDriverName() == 'mssql' || $db->getDriverName() == 'dblib') {
$data = new CDbExpression('CONVERT(VARBINARY(MAX), ' . $db->quoteValue($data) . ')');
}
if ($db->createCommand()->select('id')->from($this->sessionTableName)->where('id=:id', array(':id' => $id))->queryScalar() === false) {
//Add needed fields to the queries
$db->createCommand()->insert($this->sessionTableName, array('id' => $id, 'data' => $data, 'expire' => $expire, 'user_id' => Yii::app()->getUser()->getId(), 'last_activity' => new CDbExpression('NOW()'), 'last_ip' => CHttpRequest::getUserHostAddress()));
} else {
$db->createCommand()->update($this->sessionTableName, array('data' => $data, 'expire' => $expire, 'user_id' => Yii::app()->getUser()->getId(), 'last_activity' => new CDbExpression('NOW()'), 'last_ip' => CHttpRequest::getUserHostAddress()), 'id=:id', array(':id' => $id));
}
} catch (Exception $e) {
$this->createSessionTable($db, $this->sessionTableName);
if (YII_DEBUG) {
echo $e->getMessage();
}
return false;
}
return true;
}
示例12: actionborrafoto
/**
* Borra el archivo de imagen en el disco
*
*
*/
public function actionborrafoto()
{
//$id=$_GET['cualfoto'];
$id = MiFactoria::cleanInput($_GET['cualfoto']);
//$ruta = Yii::app()->params['rutafotosinventario'];
if (strpos($id, "_") > 0) {
$identidad = substr($id, 0, strpos($id, "_"));
} else {
$identidad = substr($id, 0, strpos($id, "."));
}
//echo "esta e e ".$identidad;
//Yii::app()->end();
$modelonue = Inventario::model()->findByPk($identidad);
//echo Fotos::devuelvenombresolo($id);
$logfotos = new Logfotosinventario();
$logfotos->ip = CHttpRequest::getUserHostAddress();
$logfotos->iduser = Yii::app()->user->id;
$logfotos->fecha = date("Y-m-d H:i:s");
$logfotos->hidinventario = $modelonue->idinventario;
$logfotos->operacion = "BORRA";
$logfotos->nombrefoto = $id;
if (!$logfotos->save()) {
print_r($logfotos->getErrors());
Yii::app()->end();
}
$modelonue->setScenario("subefoto");
$modelonue->clasefoto = 'X';
if (!$modelonue->save()) {
print_r($modelonue->getErrors());
Yii::app()->end();
}
echo CHtml::image(Yii::app()->params['imagenes'] . 'eliminado.png', '', array('width' => 40, 'height' => 50));
unlink(trim(Yii::getPathOfAlias('webroot.fotosinv') . DIRECTORY_SEPARATOR . $modelonue->codpropietario . DIRECTORY_SEPARATOR . $id));
/*$nombrearchivo='IMG_0059.JPG';
//$ruta='d:\web\motoristas\assets\FOTOS\G00001.JPG';
//$ruta='d:/web/motoristas/assets/FOTOS/G00001.JPG';
$rutadir=Yii::app()->params['rutafotosinventario'];
$ruta=Yii::app()->params['rutafotosinventario'].$nombrearchivo;
//$miarchivo=Yii::app()->CFile->getInstance(Yii::app()->params['rutafotosinventario'].trim($nombrearchivo));
//$miarchivo=Yii::app()->CFile->getInstance("");\\192.168.26.100\web\motoristas\assets\FOTOS
// $miarchivo->set(Yii::app()->params['rutafotosinventario'].trim($nombrearchivo));
//$miarchivo->set($miarchivo->getRealPath(Yii::app()->params['rutafotosinventario'].trim($nombrearchivo)));
//echo $miarchivo->getRealPath(Yii::app()->params['rutafotosinventario'].trim($nombrearchivo));
//echo "El tamno es ".$miarchivo->size;
if ( file_exists($ruta))
//\\192.168.26.100\web\motoristas\assets\FOTOS
{ echo "si existe ". PHP_OS." <br>";
echo " ". (!strncasecmp(PHP_OS, 'win', 3))." ";
$miarchivo=Yii::app()->CFile->getInstance($ruta);
// $miarchivo->set($miarchivo->getRealPath($rutadir.$nombrearchivo));
//echo $miarchivo->getRealPath($rutadir);
echo "El tamno es ".$miarchivo->size;
} else
{
echo "no existe";
}
//if($miarchivo->delete()) {echo Yii::app()->params['rutafotosinventario'].trim($nombrearchivo).$miarchivo->realPath."se borrro";}else{ echo Yii::app()->params['rutafotosinventario'].trim($nombrearchivo).$miarchivo->realPath."nos peudo borra";}
*/
}
示例13: beforeSave
public function beforeSave()
{
if (parent::beforeSave()) {
if ($this->isNewRecord) {
$this->pubdate = time();
$this->approved = self::APPROVED_PUBLISHED;
$this->agent = CHttpRequest::getUserAgent();
$this->uid = Yii::app()->user->id;
$this->ip = CHttpRequest::getUserHostAddress();
$this->author = Yii::app()->user->name;
$this->url = Yii::app()->request->getRequestUri();
$this->email = Profile::model()->getEmail();
} else {
}
return true;
} else {
return false;
}
}
示例14: isset
<div class="dashboard-top">
<img width="80" height="80" class="left" alt="" src="<?php
echo Yii::app()->theme->baseUrl;
?>
/images/user.jpg">
<div style="width:800px;" class="right">
<p>Welcome <span class="red-txt"><b><?php
echo isset($model['first_name']) ? $model['first_name'] : null;
?>
</b></span><a class="red-txt right" href="/store/site/logout">Logout</a></p>
<p class="clear"><span>Last Login</span> : <?php
echo date("d-M-Y h A", strtotime($model['last_login_time']));
?>
, <span>Login IP</span>: <?php
echo CHttpRequest::getUserHostAddress();
?>
<span class="right">Date : <?php
echo date('d M Y');
?>
</span></p>
<p class="clear"><span>Email</span>: <a href="<?php
echo $model['email_id'];
?>
"><?php
echo $model['email_id'];
?>
</a>,
<span>Contact no</span>: <?php
echo isset($model['mobile']) ? $model['mobile'] : null;
?>
</p>