【PHP开发篇】一个统计客户端商机提交的获取IP地址

时间:2024-01-01 20:56:45

1.对客服提交数据的ip地址记录。

获取ip地址的方法:

        public function getIP()
{
global $ip;
if (getenv("HTTP_X_REAL_IP"))
$ip = getenv("HTTP_X_REAL_IP");
else if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknow"; return $ip;
}

ajax提交的请求处理function

     /*
* ajax提交商机信息
*/
public function ajaxPushAction(){
$this->getRequest()->isPost() && $this->post = $this->getRequest()->getPost();
if(!$this->post['t_name'] || !$this->post['t_tel']){
$res = -;
Comm_Tools::renderJson($res);
}
$getip = $this->getIP();
$this->post['getip'] = $getip;
$url = "http://home.demo.cn/web/buss/ajaxPushBusinessToQueue";
$res = Comm_Tools::curl($url, 'POST', $this->post);
Comm_Tools::renderJson($res);
}