{"id":27888,"date":"2021-05-14T10:14:00","date_gmt":"2021-05-14T07:14:00","guid":{"rendered":"https:\/\/themewp.inform.click\/?p=27888"},"modified":"2021-10-17T04:58:46","modified_gmt":"2021-10-17T01:58:46","slug":"hur-far-jag-geolocation-fran-ip-i-php","status":"publish","type":"post","link":"https:\/\/themewp.inform.click\/sv\/hur-far-jag-geolocation-fran-ip-i-php\/","title":{"rendered":"Hur f\u00e5r jag Geolocation fr\u00e5n IP i PHP"},"content":{"rendered":"<p>Letar du efter ett s\u00e4tt att h\u00e4mta anv\u00e4ndarens Geolocation fr\u00e5n IP-adress i PHP? Med hj\u00e4lp av Geolocation skulle du veta var dina webbplatsbes\u00f6kare finns. Den kan anv\u00e4ndas f\u00f6r m\u00e5lgruppens syfte. Baserat p\u00e5 anv\u00e4ndarens plats kan du visa relevant inneh\u00e5ll f\u00f6r dem.<\/p>\n<p>Vi vet att lokalisera anv\u00e4ndarens position HTML5 Geolocation API \u00e4r tillg\u00e4ngligt. Men detta API fungerar med tillst\u00e5ndsbasis. Det popups en anv\u00e4ndare och ber om deras beh\u00f6righeter d\u00e5 bara det fungerar.<\/p>\n<p>F\u00f6r att \u00f6vervinna denna situation finns det en tj\u00e4nst som \u00e4r <a href=\"https:\/\/ipstack.com\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">ipstack<\/a>. I den h\u00e4r artikeln studerar vi hur man f\u00e5r Geolocation fr\u00e5n IP i PHP med ipstack-tj\u00e4nsten.<\/p>\n<h3>Skaffa en API-nyckel<\/h3>\n<p>F\u00f6r att komma ig\u00e5ng m\u00e5ste du f\u00f6rst registrera dig p\u00e5 <a href=\"https:\/\/ipstack.com\/product\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">ipstack<\/a>. ipstack tillhandah\u00e5ller olika niv\u00e5er av tj\u00e4nster som str\u00e4cker sig fr\u00e5n gratis till f\u00f6retagsniv\u00e5. Om du anv\u00e4nder den h\u00e4r tj\u00e4nsten f\u00f6rsta g\u00e5ngen rekommenderar vi att du g\u00e5r gratisplaner f\u00f6rst. N\u00e4r denna artikel skrivs till\u00e5ter gratis tj\u00e4nst 10000 f\u00f6rfr\u00e5gningar per m\u00e5nad. Det betyder att du kan kontrollera 10000 IP: s Geolocation gratis varje m\u00e5nad.<\/p>\n<p>N\u00e4r du registrerat dig hos ipstack f\u00e5r du din \u00e5tkomstnyckel. Denna nyckel kr\u00e4vs n\u00e4r vi ger ett API-samtal till ipstack.<\/p>\n<p>Nedan \u00e4r sk\u00e4rmdumpen av din ipstack-instrumentpanel d\u00e4r du kan kopiera \u00e5tkomstnyckeln.<\/p>\n<p><a href=\"https:\/\/themewp.inform.click\/wp-content\/uploads\/2021\/04\/post-20620-60820fdb890eb.png\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/themewp.inform.click\/wp-content\/uploads\/2021\/04\/post-20620-60820fdb890eb.png\" alt=\"Hur f\u00e5r jag Geolocation fr\u00e5n IP i PHP\" ><\/a><\/p>\n<h3>F\u00e5 Geolocation fr\u00e5n IP i PHP<\/h3>\n<p>Vid den h\u00e4r tiden har vi skapat ett konto med ipstack och vi har v\u00e5r \u00e5tkomstnyckel. Nu kan vi b\u00f6rja anv\u00e4nda deras tj\u00e4nst och f\u00e5 Geolocation fr\u00e5n IP-adress. Eftersom vi beh\u00f6ver ge ett API-samtal till ipstack skulle vi anv\u00e4nda PHP cURL f\u00f6r att ge ett API-samtal. Anv\u00e4ndaren kan ocks\u00e5 anv\u00e4nda <a href=\"https:\/\/themewp.inform.click\/sv\/hur-man-anvander-guzzle-en-php-http-klient-for-att-skicka-http-forfragningar\/\" title=\"Guzzle\">Guzzle<\/a> ist\u00e4llet f\u00f6r cURL.<\/p>\n<p>L\u00e5t oss s\u00e4ga att vi m\u00e5ste hitta Geolocation av en IP &#8217;103.47.153.189&#8217;. S\u00e5 vi skriver koden f\u00f6r det enligt nedan.<\/p>\n<pre><code>&lt;?php\n\/\/ set API Access Key\n$access_key = 'YOUR_ACCESS_KEY';\n\u00a0\n\/\/ set phone number\n$ip_address = '103.47.153.189';\n\u00a0\n\/\/ Initialize CURL:\n$ch = curl_init('http:\/\/api.ipstack.com\/'. $ip_address .'?access_key='. $access_key);\u00a0 \ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\u00a0\n\/\/ Store the data:\n$json = curl_exec($ch);\ncurl_close($ch);\n?&gt;<\/code><\/pre>\n<p>I geng\u00e4ld f\u00e5r du svar som:<\/p>\n<pre><code>{  \n   \"ip\":\"103.47.153.189\",\n   \"type\":\"ipv4\",\n   \"continent_code\":\"AS\",\n   \"continent_name\":\"Asia\",\n   \"country_code\":\"IN\",\n   \"country_name\":\"India\",\n   \"region_code\":\"MH\",\n   \"region_name\":\"Maharashtra\",\n   \"city\":\"Pune\",\n   \"zip\":\"411001\",\n   \"latitude\":18.5333,\n   \"longitude\":73.8667,\n   \"location\":{  \n      \"geoname_id\":1259229,\n      \"capital\":\"New Delhi\",\n      \"languages\":[  \n         {  \n            \"code\":\"hi\",\n            \"name\":\"Hindi\",\n            \"native\":\"u0939u093fu0928u094du0926u0940\"\n         },\n         {  \n            \"code\":\"en\",\n            \"name\":\"English\",\n            \"native\":\"English\"\n         }\n      ],\n      \"country_flag\":\"http:\/\/assets.ipstack.com\/flags\/in.svg\",\n      \"country_flag_emoji\":\"ud83cuddeeud83cuddf3\",\n      \"country_flag_emoji_unicode\":\"U+1F1EE U+1F1F3\",\n      \"calling_code\":\"91\",\n      \"is_eu\":false\n   }\n}\n<\/code><\/pre>\n<p>Du kan se hur mycket information vi kan f\u00e5 genom att bara skicka en IP-adress. Vi f\u00e5r n\u00e4stan all information man kan beh\u00f6va fr\u00e5n IP. En anv\u00e4ndare kan ocks\u00e5 skicka flera IP-adresser med kommaseparerade.<\/p>\n<p>Vi hoppas att du kan l\u00e4ra dig hur du f\u00e5r Geolocation fr\u00e5n IP i PHP. Vi vill h\u00f6ra dina tankar i kommentarsektionen nedan.<\/p>\n<h4>relaterade artiklar<\/h4>\n<ul>\n<li><a href=\"https:\/\/themewp.inform.click\/sv\/hitta-geolocation-med-ip-adress-gratis-i-php\/\" title=\"Hitta Geolocation med IP-adress gratis i PHP\">Hitta Geolocation med IP-adress gratis i PHP<\/a><\/li>\n<li><a href=\"https:\/\/themewp.inform.click\/sv\/mailboxlayer-ett-gratis-och-kraftfullt-api-for-att-kontrollera-om-e-post-ar-giltig-riktig-e-post\/\" title=\"mailboxlayer - Ett gratis och kraftfullt API f\u00f6r att kontrollera om e-post \u00e4r giltig (riktig e-post)\">mailboxlayer &#8211; Ett gratis och kraftfullt API f\u00f6r att kontrollera om e-post \u00e4r giltig (riktig e-post)<\/a><\/li>\n<li><a href=\"https:\/\/themewp.inform.click\/sv\/kickbox-ett-e-postverifieringsbibliotek-i-realtid-for-php\/\" title=\"Kickbox - Ett e-postverifieringsbibliotek i realtid f\u00f6r PHP\">Kickbox &#8211; Ett e-postverifieringsbibliotek i realtid f\u00f6r PHP<\/a><\/li>\n<\/ul>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Inspelningsk\u00e4lla:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/artisansweb.net\" class=\"external external_icon\">artisansweb.net<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Letar du efter ett s\u00e4tt att h\u00e4mta anv\u00e4ndarens Geolocation fr\u00e5n IP-adress i PHP? Med hj\u00e4lp av Geolocation skulle du veta var din webbplats &#8230;<\/p>\n","protected":false},"author":1,"featured_media":20621,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[279],"tags":[850],"class_list":["post-27888","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-10","tag-affiai-sv"],"_links":{"self":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts\/27888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/comments?post=27888"}],"version-history":[{"count":0,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/posts\/27888\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/media\/20621"}],"wp:attachment":[{"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/media?parent=27888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/categories?post=27888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themewp.inform.click\/sv\/wp-json\/wp\/v2\/tags?post=27888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}