Пример #1
0
 /**
  * testClientProperties method
  *
  * @access public
  * @return void
  */
 function testClientProperties()
 {
     $_SERVER['HTTP_HOST'] = 'localhost:80';
     $this->assertEqual($this->RequestHandler->getReferrer(), 'localhost');
     $_SERVER['HTTP_HOST'] = null;
     $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
     $this->assertEqual($this->RequestHandler->getReferrer(), 'cakephp.org');
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com';
     $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
     $_SERVER['REMOTE_ADDR'] = '192.168.1.3';
     $this->assertEqual($this->RequestHandler->getClientIP(false), '192.168.1.5');
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
     unset($_SERVER['HTTP_X_FORWARDED_FOR']);
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
     unset($_SERVER['HTTP_CLIENT_IP']);
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.3');
     $_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1';
     $this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2');
 }
Пример #2
0
 /**
 * Used to perform comment related Api calls.
 *
 * @param array $comment
 * @param string $type
 * @return string
 */
 function __commentCall($comment, $type = 'comment-check')
 {
     if (empty($this->apiKey)) {
         // People will go crazy if they don't figure out they need an Api, so let's make there live
         // a little easier ; ).
         trigger_error('Akismet::checkComment() failed: No Akismet Api key has been set.', E_USER_WARNING);
         return false;
     }
     $vars = array();
     // We use the RequestHandlerComponent in order to figure out the Client-IP and Referrer
     //loadComponent('RequestHandler');
     if (!isset($comment['blog'])) {
         $vars['blog'] = FULL_BASE_URL;
     }
     if (!isset($comment['user_ip'])) {
         $vars['user_ip'] = RequestHandlerComponent::getClientIP();
     }
     if (!isset($comment['referrer '])) {
         $vars['referrer '] = RequestHandlerComponent::getReferrer();
     }
     if (!isset($comment['user_agent'])) {
         $vars['user_agent'] = env('HTTP_USER_AGENT');
     }
     $url = 'http://' . $this->apiKey . '.rest.akismet.com/1.1/' . $type;
     $vars = array_merge($vars, $comment);
     $headers = array();
     $headers[] = 'User-Agent: ' . $this->userAgent;
     return $this->httpPost($url, $vars, $headers);
 }