🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۵ امیرحسین شکری
مشکل در دریافت لوکیشن
جامعه پی اچ پی ایجاد شده در ۲۹ شهریور ۱۳۹۹

دوستان من با وجود استفاده از dns سایت shecan و همچنین vpn باز هم نتونستم از geolocation استفاده کنم.
چه راه حلی پیشنهاد میکنید؟

سلام و احترام

شما میتونید از api خود geolocation هم استفاده کنید.

صدا زدن api به این صورت است:

http://www.geoplugin.net/php.gp?ip=xx.xx.xx.xx

در قسمت x‌ها شما میتونید ip کاربر را به شکل زیر دریافت کنید و قرار دهید

  echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));

array (
  'geoplugin_request' => '46.224.69.148',
  'geoplugin_status' => 206,
  'geoplugin_delay' => '0ms',
  'geoplugin_credit' => 'Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.',
  'geoplugin_city' => '',
  'geoplugin_region' => '',
  'geoplugin_regionCode' => '',
  'geoplugin_regionName' => '',
  'geoplugin_areaCode' => '',
  'geoplugin_dmaCode' => '',
  'geoplugin_countryCode' => 'IR',
  'geoplugin_countryName' => 'Iran',
  'geoplugin_inEU' => 0,
  'geoplugin_euVATrate' => false,
  'geoplugin_continentCode' => 'AS',
  'geoplugin_continentName' => 'Asia',
  'geoplugin_latitude' => '35.698',
  'geoplugin_longitude' => '51.4115',
  'geoplugin_locationAccuracyRadius' => '50',
  'geoplugin_timezone' => 'Asia/Tehran',
  'geoplugin_currencyCode' => 'IRR',
  'geoplugin_currencySymbol' => '﷼',
  'geoplugin_currencySymbol_UTF8' => '﷼',
  'geoplugin_currencyConverter' => '42105',

 

یک کلاس کاربردی هم برای این قضیه نوشته شده تا بتونی ازش خیلی راحت استفاده کنید. میتونی به این لینک

یه سری بزنی

 

امیر صالحی ۲۹ شهریور ۱۳۹۹، ۱۸:۲۸

سپاس امیر جان. پس یعنی کلا متد locate توی فایل js رو بیخیال بشیم و دکمه findLocation توی html رو مستقیم وصل کنیم به این کلاس php؟ درسته؟

امیرحسین شکری ۳۰ شهریور ۱۳۹۹، ۰۷:۰۷

امیر جان سلام مجدد.
من فایل کلاسشو دانلود کردم و گذاشتم تو پوشه assets و توی init.php درست قبل از lib-locations اضافش کردم. به این شکل:

require_once(BASE_PATH . "assets/geoPlugin/geoplugin.class.php");
include BASE_PATH . "libs/lib-locations.php";

بعد توی فایل lib-locations کد زیر رو نوشتم و خروجی گرفتم:

echo "<pre style='direction: ltr; text-align:left;'>";
echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));
echo "</pre>"; 
//output:
  'geoplugin_request' => '::1',
  'geoplugin_status' => 404,
  'geoplugin_delay' => '1ms',
  'geoplugin_credit' => 'Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\\\'http://www.maxmind.com\\\'>http://www.maxmind.com</a>.',
  'geoplugin_city' => NULL,
  'geoplugin_region' => NULL,
  'geoplugin_regionCode' => NULL,
  'geoplugin_regionName' => NULL,
  'geoplugin_areaCode' => NULL,
  'geoplugin_dmaCode' => NULL,
  'geoplugin_countryCode' => NULL,
  'geoplugin_countryName' => NULL,
  'geoplugin_inEU' => 0,
  'geoplugin_euVATrate' => false,
  'geoplugin_continentCode' => NULL,
  'geoplugin_continentName' => NULL,
  'geoplugin_latitude' => NULL,
  'geoplugin_longitude' => NULL,
  'geoplugin_locationAccuracyRadius' => NULL,
  'geoplugin_timezone' => NULL,
  'geoplugin_currencyCode' => NULL,
  'geoplugin_currencySymbol' => NULL,
  'geoplugin_currencySymbol_UTF8' => '',
  'geoplugin_currencyConverter' => '0',

انگار SERVER['REMOTE_ADDR'] آی پی ::۱ رو پاس میده.
وقتی ip خودم رو بهش دادم، خروجی شد دقیقا عین خروجی که شما تو پاسخ اول گذاشتی. ولی خب مختصات تهران رو داد که مال isp بود فک کنم.

از کد زیر هم در فایل lib-locations خروجی گرفتم (مطابق داکیومنتیشن). یکبار SERVER['REMOTE_ADDR'] رو پاس دادم و یکبار ip خودم رو. هیچکدوم نتیجه نداد:

$geoplugin = new geoPlugin();
$geoplugin->locate();
//output:
Notice:  Undefined index: euVATrate in C:\xampp\htdocs\...\geoplugin.class.php on line 104
Geolocation results for {my_ip}:
City:
Region:
Region Code:
Region Name:
DMA Code:
Country Name:
Country Code:
In the EU?: 0
EU VAT Rate:
Latitude:
Longitude:
Radius of Accuracy (Miles):
Timezone:
Currency Code:
Currency Symbol:
Exchange Rate: 0
امیرحسین شکری ۰۱ مهر ۱۳۹۹، ۱۱:۱۲

سلام و احترام

آی پی ::۱ رو نمیشه کاریش کرد چون ما داریم توی local host کار میکنیم و آی پی به همین شکله ولی اگه ما این پروژه رو توی یه سرور واقعی قرار بدیم قطعا به درستی کار میکنه. 

متد locate به عنوان ورودی آی پی هم دریافت میکنه که شما میتونه برای تست یه آی پی دلخواه بدید تا تستاتونو انجام بدید

$geoplugin->locate('78.129.204.100');

Geolocation results for 78.129.204.100:
City: Stoke Newington
Region: England
Region Code: HCK
Region Name: Hackney
DMA Code:
Country Name: United Kingdom
Country Code: GB
In the EU?: 1
EU VAT Rate:
Latitude: 51.5638
Longitude: -0.0765
Radius of Accuracy (Miles): 1000
Timezone: Europe/London
Currency Code: GBP
Currency Symbol: £
Exchange Rate: 0.7729
At todays rate, US$100 will cost you £77.29
Some places you may wish to visit near Stoke Newington: 
1:
	 Place: Finsbury Park
	 Region: England
	 Latitude: 51.5692900
	 Longitude: -0.1069100
2:
	 Place: Highbury
	 Region: England
	 Latitude: 51.5500000
	 Longitude: -0.1000000
3:
	 Place: Hornsey
	 Region: England
	 Latitude: 51.5875200
	 Longitude: -0.1220400
4:
	 Place: Shoreditch
	 Region: England
	 Latitude: 51.5250900
	 Longitude: -0.0769500
5:
	 Place: Kings Cross
	 Region: England
	 Latitude: 51.5429900
	 Longitude: -0.1308100

 

امیر صالحی ۱۰ مهر ۱۳۹۹، ۰۷:۳۲

سلام و احترامی دوباره

امیر حسین جان، من با iP خودم هم تست گرفتم و یه آی پی امریکایی رو هم تست کردم، یه سری مشخصاتو به هر آی پی نمیده انگار، آی پی خودم که زدم کامل‌تر بود نسبت به آی پی امریکا.

Geolocation results for 46.***.**.**:
City:
Region:
Region Code:
Region Name:
DMA Code:
Country Name: Iran
Country Code: IR
In the EU?: 0
EU VAT Rate:
Latitude: 35.***
Longitude: 51.****
Radius of Accuracy (Miles): 50
Timezone: Asia/Tehran
Currency Code: IRR
Currency Symbol: ﷼
Exchange Rate: 42104.9997
At todays rate, US$100 will cost you ﷼4210499.97
Some places you may wish to visit near : 
1:
	 Place: Javādīyeh
	 Region: Tehrān
	 Latitude: 35.6493000
	 Longitude: 51.3869000
2:
	 Place: Ţarasht
	 Region: Tehrān
	 Latitude: 35.7081000
	 Longitude: 51.3456000
3:
	 Place: Qal‘eh Morghī
	 Region: Tehrān
	 Latitude: 35.6500000
	 Longitude: 51.3666700
4:
	 Place: Kāzemābād
	 Region: Tehrān
	 Latitude: 35.7522222
	 Longitude: 51.4697222
5:
	 Place: Khānīābād
	 Region: Tehrān
	 Latitude: 35.6276000
	 Longitude: 51.3862000

 

امیر صالحی ۱۱ مهر ۱۳۹۹، ۱۴:۵۴