function amend($rrr) { require_once 'ip.php'; //$ip1 = $_SERVER['REMOTE_ADDR']; $ip1 = "122.200.86.153"; $iplocation = new iplocate(); $address = $iplocation->getaddress($ip1); $iparea = $address['area1'] . $address['area2']; echo $iparea; //$exe = mysql_query( "insert into ssc_memberamend set uid = '".$_SESSION["uid"]."',username = '******',level = '".$_SESSION["level"]."', cont='".$rrr."', ip='".$ip1."', area='".$iparea."', adddate='".date("Y-m-d H:i:s")."'"); //return $rrr; }
public function index() { $root = array(); $client_ip = strim($GLOBALS['request']['client_ip']); if (empty($client_ip)) { $client_ip = get_client_ip(); } $root['ip'] = $client_ip; $root['ip_city_name'] = ''; $root['ip_city_id'] = 0; //设置如存在的IP订位 if (file_exists(APP_ROOT_PATH . "system/extend/ip.php")) { require_once APP_ROOT_PATH . "system/extend/ip.php"; $iplocation = new iplocate(); $address = $iplocation->getaddress($client_ip); $root['address'] = $address; //$root['ip_city_name'] = str_replace('市', '', $address['area1']); $root['ip_city_id'] = 0; if (mb_strpos($address['area1'], '省', 0, 'utf-8') === false) { $root['ip_city_name'] = $address['area1']; } else { $ipos = intval(mb_strpos($address['area1'], '省', 0, 'utf-8')); $root['ip_city_name'] = mb_substr($address['area1'], $ipos + 1, 10, 'utf-8'); } $root['ip_city_name'] = str_replace('市', '', $root['ip_city_name']); $sql = "select * from " . DB_PREFIX . "deal_city where is_delete = 0 and is_effect = 1 "; $city_list = $GLOBALS['db']->getAll($sql); //不知谁把$city_list 查询去掉了; 去掉后就不能通过ip定位了; chenfq 现在又添加上去了 2014-09-18 foreach ($city_list as $city) { if (strpos($address['area1'], $city['name'])) { $deal_city = $city; $root['ip_city_id'] = $city['id']; break; } } } if (!$deal_city) { $deal_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_default = 1 and is_effect = 1 and is_delete = 0"); } $root['city_name'] = $deal_city['name']; $root['city_id'] = $deal_city['id']; output($root); }
public static function locate_city($city_py = "") { if (!$city_py) { $city_py = strim($_GET['city']); } if ($city_py) { $current_city = es_session::get("current_city"); //强行定位 if ($current_city['uname'] != $city_py && $current_city['id'] != $city_py) { $current_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where (uname = '" . $city_py . "' or id = '" . $city_py . "') and is_effect = 1"); } } if (empty($current_city)) { //无城市,由session中获取 $current_city = es_session::get("current_city"); } if (empty($current_city)) { $city_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_city where is_effect = 1"); //自动定位 require_once APP_ROOT_PATH . "system/extend/ip.php"; $ip = CLIENT_IP; $iplocation = new iplocate(); $address = $iplocation->getaddress($ip); foreach ($city_list as $city) { if (strpos($address['area1'], $city['name'])) { $current_city = $city; break; } } } if (empty($current_city)) { $current_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_default = 1 and is_effect = 1"); } es_session::set("current_city", $current_city); return $current_city; }
/** * 定位城市 * @param int $deal_city_id 城市id * @return unknown */ function get_cur_deal_city($deal_city_id = 0) { if ($deal_city_id > 0) { $deal_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_effect = 1 and is_delete = 0 and id = " . intval($deal_city_id)); } if (!$deal_city) { //设置如存在的IP订位 if (file_exists(APP_ROOT_PATH . "system/extend/ip.php")) { require_once APP_ROOT_PATH . "system/extend/ip.php"; $ip = get_client_ip(); $iplocation = new iplocate(); $address = $iplocation->getaddress($ip); $sql = "select * from " . DB_PREFIX . "deal_city where is_delete = 0 and is_effect = 1 "; $city_list = $GLOBALS['db']->getAll($sql); //不知谁把$city_list 查询去掉了; 去掉后就不能通过ip定位了; chenfq 现在又添加上去了 2014-09-18 foreach ($city_list as $city) { if (strpos($address['area1'], $city['name'])) { $deal_city = $city; break; } } } if (!$deal_city) { $deal_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_default = 1 and is_effect = 1 and is_delete = 0"); } } return $deal_city; }
/** * 获取当前团购城市 */ function get_current_deal_city() { if (es_cookie::is_set("deal_city")) { $deal_city_id = es_cookie::get("deal_city"); $deal_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_effect = 1 and is_delete = 0 and id = " . intval($deal_city_id)); } if (!$deal_city) { //设置如存在的IP订位 if (file_exists(APP_ROOT_PATH . "system/extend/ip.php")) { require_once APP_ROOT_PATH . "system/extend/ip.php"; $ip = get_client_ip(); $iplocation = new iplocate(); $address = $iplocation->getaddress($ip); foreach ($city_list as $city) { if (strpos($address['area1'], $city['name'])) { $deal_city = $city; break; } } } if (!$deal_city) { $deal_city = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_city where is_default = 1 and is_effect = 1 and is_delete = 0"); } } return $deal_city; }
/** * 获取当前团购城市 */ function getCurrentDealCity() { $model = M("City"); if ($city = $_GET['city']) { $deal_city = $model->where("city_py='{$city}'")->find(); } else { if ($city_id = cookie('deal_city')) { $deal_city = $model->where("id={$city_id}")->find(); } else { //导入Ip类 Vendor('IP.ip'); $ip = get_client_ip(); $iplocation = new iplocate(); $address = $iplocation->getaddress($ip); $city_list = $model->select(); foreach ($city_list as $city) { if (strpos($address['area1'], $city['city'])) { $deal_city = $city; break; } } if (!$deal_city) { $default = C("DEFAULT_CITY"); $deal_city = $model->where("id={$default}")->find(); } } } cookie("deal_city", $deal_city['id']); return $deal_city; }