本文整理汇总了PHP中CakeRequest::referer方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeRequest::referer方法的具体用法?PHP CakeRequest::referer怎么用?PHP CakeRequest::referer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeRequest
的用法示例。
在下文中一共展示了CakeRequest::referer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* beforeSave is called before a model is saved. Returning false from a beforeSave callback
* will abort the save operation.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
*
* @return mixed|void
*/
public function beforeSave(\Model $model, $options = array())
{
parent::beforeSave($model);
$request = new CakeRequest();
$data = ['blog' => urlencode(Configure::read('General.site_url')), 'user_ip' => urlencode($model->data[$model->alias]['author_ip']), 'user_agent' => urlencode($model->data[$model->alias]['agent']), 'referrer' => urlencode($request->referer()), 'permalink' => urlencode($request->referer()), 'comment_type' => urlencode('comment'), 'comment_author' => urlencode($model->data[$model->alias]['author']), 'comment_author_email' => urlencode($model->data[$model->alias]['author_email']), 'comment_author_url' => urlencode($model->data[$model->alias]['author_url']), 'comment_content' => urlencode($model->data[$model->alias]['content'])];
if (Akismet::isSpam($data, Configure::read('Akismet.api_key'))) {
$model->data[$model->alias]['status'] = 'spam';
}
}
示例2: referer
/**
* Returns the referring URL for this request.
*
* @param string $default Default URL to use if HTTP_REFERER cannot be read from headers
* @param bool $local If true, restrict referring URLs to local server
* @return string Referring URL
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer
*/
public function referer($default = null, $local = false)
{
if (!$this->request) {
return '/';
}
$referer = $this->request->referer($local);
if ($referer === '/' && $default && $default !== $referer) {
return Router::url($default, !$local);
}
return $referer;
}
示例3: testRefererBasePath
/**
* Test referer() with a base path that duplicates the
* first segment.
*
* @return void
*/
public function testRefererBasePath()
{
$request = new CakeRequest('some/path');
$request->url = 'users/login';
$request->webroot = '/waves/';
$request->base = '/waves';
$request->here = '/waves/users/login';
$_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/waves/waves/add';
$result = $request->referer(true);
$this->assertSame($result, '/waves/add');
}
示例4: testReferer
/**
* test the referer function.
*
* @return void
*/
public function testReferer()
{
$request = new CakeRequest('some/path');
$request->webroot = '/';
$_SERVER['HTTP_REFERER'] = 'http://cakephp.org';
$result = $request->referer();
$this->assertSame($result, 'http://cakephp.org');
$_SERVER['HTTP_REFERER'] = '';
$result = $request->referer();
$this->assertSame($result, '/');
$_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
$result = $request->referer(true);
$this->assertSame($result, '/some/path');
$_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
$result = $request->referer(false);
$this->assertSame($result, FULL_BASE_URL . '/some/path');
$_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
$result = $request->referer(true);
$this->assertSame($result, '/some/path');
$_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/recipes/add';
$result = $request->referer(true);
$this->assertSame($result, '/recipes/add');
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
$result = $request->referer();
$this->assertSame($result, 'cakephp.org');
}
示例5: getReferer
/**
* Gets the server name from which this request was referred
*
* @return string Server address
* @deprecated use $this->request->referer() from your controller instead
*/
public function getReferer()
{
return $this->request->referer(false);
}
示例6: _get_request
/**
* @param $data
*
* @return mixed
*/
protected function _get_request($data)
{
$request = new CakeRequest();
$data['request_user_agent'] = $request::header('User-Agent');
$data['request_client_ip'] = $request->clientIp();
$data['request_method'] = $request->method();
$data['request_referer'] = $request->referer();
$data['request_url'] = Router::url(null, true);
return $data;
}
示例7: getReferer
/**
* Gets the server name from which this request was referred
*
* @return string Server address
* @deprecated 3.0.0 Use $this->request->referer() from your controller instead
*/
public function getReferer()
{
return $this->request->referer(FALSE);
}