Example #1
0
 /**
  * UtilityTest::testGetReferer()
  *
  * @covers Utility::getReferer
  * @return void
  */
 public function testGetReferer()
 {
     $res = Utility::getReferer();
     $this->assertEquals(env('HTTP_REFERER'), $res);
     $res = Utility::getReferer(true);
     $this->assertEquals(env('HTTP_REFERER'), $res);
     $_SERVER['HTTP_REFERER'] = '/foo/bar';
     $res = Utility::getReferer(true);
     $base = Configure::read('App.fullBaseUrl');
     if (!$base) {
         $base = 'http://localhost';
     }
     $this->assertEquals($base . env('HTTP_REFERER'), $res);
 }
Example #2
0
 /**
  * Append some more infos to better track down the error
  *
  * @return string
  */
 public static function traceDetails()
 {
     if (empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/test.php?') === 0) {
         return null;
     }
     $currentUrl = Router::url();
     //isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'n/a';
     $refererUrl = Utility::getReferer();
     //Router::getRequest()->url().'
     $uid = !empty($_SESSION) && !empty($_SESSION['Auth']['User']['id']) ? $_SESSION['Auth']['User']['id'] : null;
     $data = array(@CakeRequest::clientIp(), $currentUrl . (!empty($refererUrl) ? ' (' . $refererUrl . ')' : ''), $uid, env('HTTP_USER_AGENT'));
     return implode(' - ', $data);
 }
Example #3
0
 /**
  * Logs attempts
  *
  * @param bool ErrorsOnly (only if error occured, otherwise always)
  * @returns null if not logged, true otherwise
  */
 protected function _logAttempt($errorsOnly = true)
 {
     if ($errorsOnly === true && empty($this->error) && empty($this->internalError)) {
         return null;
     }
     if (!$this->settings[$this->Model->alias]['log']) {
         return null;
     }
     $msg = 'IP \'' . Utility::getClientIp() . '\', Agent \'' . env('HTTP_USER_AGENT') . '\', Referer \'' . env('HTTP_REFERER') . '\', Host-Referer \'' . Utility::getReferer() . '\'';
     if (!empty($this->error)) {
         $msg .= ', ' . $this->error;
     }
     if (!empty($this->internalError)) {
         $msg .= ' (' . $this->internalError . ')';
     }
     $this->log($msg, 'captcha');
     return true;
 }
 /**
  * get the current referer
  * @param bool $full (defaults to false and leaves the url untouched)
  * @return string $referer (local or foreign)
  * 2011-11-02 ms
  */
 public static function getReferer($full = false)
 {
     return Utility::getReferer($full);
 }