darkfreaks Posted May 26, 2009 Share Posted May 26, 2009 ok so im trying to view the site with an ip of 70.112.156.140 but it tells me i am banned even though its a united states address. maybe the lack of range of adresses in the database? i would need the range of adresses for this IP Example from database: 0000000000,0000000000, UNITED STATES Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/ Share on other sites More sharing options...
Maq Posted May 26, 2009 Share Posted May 26, 2009 I have no clue what you're talking about, could you post a link from the previous thread? Or elaborate a bit more? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842623 Share on other sites More sharing options...
darkfreaks Posted May 26, 2009 Author Share Posted May 26, 2009 http://www.phpfreaks.com/forums/index.php/topic,253561.0.html Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842629 Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 are you looking, for a geo something type of application? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842632 Share on other sites More sharing options...
darkfreaks Posted May 26, 2009 Author Share Posted May 26, 2009 yeah i currently have a CSV file that reads ranges of IP's but its not very accurate, know any better ones out there ??? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842636 Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 i min bro just looking, i think there one on here somewhere, that use curl would that be ok? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842638 Share on other sites More sharing options...
darkfreaks Posted May 26, 2009 Author Share Posted May 26, 2009 yeah that would be because that would pull it off a more accurate website. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842640 Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 have you seen this one sorry looking for the code so sorry. sorry double posted here sorry admin. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842644 Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 try this please should work easy to use. http://www.codediesel.com/tools/free-geolocation-api-tool/ Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-842646 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 how do i take that curl script and create something that willcompare the person's IP to the GEO IP database and return the country United States and if it matches to let them enter the site else put up a message if it doesnt match United states? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843227 Share on other sites More sharing options...
cunoodle2 Posted May 27, 2009 Share Posted May 27, 2009 How about this... <?php <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ return curl_exec($ch); } $location_data = get_ip_location("70.112.156.140"); //here you could use a regular expression or something along those lines to extract the information that is between "<CountryName>" and "</CountryName>" (I'll let you figure that one out on your own or see if someone else here can do it for you. //from there just use your previous code to check and see if the country name matches your if statements ?> REMEMBER to trim your data (we had that big issue last time ;-) ) Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843243 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 i got one question instead of manually inputting an IP into the code like they have can i do something like $IP_location= get_ip_location($SERVER[REMOTE_ADDR); then use if statements to compare the country? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843274 Share on other sites More sharing options...
cunoodle2 Posted May 27, 2009 Share Posted May 27, 2009 Yes, absolutely can be done without issue. I was doing that just for example reasons. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843282 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 now i just need to get the response between <countryname> </countryname> xml tags anyone got any idea ??? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843294 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 Hello, I have extended the code a bit in order to get the <CountryName></CountryName> node from xml string. <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ $response = curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryName; } } $location_data = get_ip_location("70.112.156.140"); //here you could use a regular expression or something along those lines to extract the information that is between "<CountryName>" and "</CountryName>" (I'll let you figure that one out on your own or see if someone else here can do it for you. //from there just use your previous code to check and see if the country name matches your if statements ?> Hope this will help. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843319 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 well the function just returns all the strings from the site i just want it to return the country Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843336 Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 well the function just returns all the strings from the site i just want it to return the country Just use a simpleXML object to grab whatever is between the country elements. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843342 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 well the function just returns all the strings from the site i just want it to return the country Try the new extended function as below: <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ $response = curl_exec($ch); /* Get CountryName */ if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryName; } } $location_data = get_ip_location("70.112.156.140"); echo $location_data; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843351 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 ok i think i got it do i just do if($xmlObj->Countryname=="United States) {} to compare Edit:nope how do i compare the country from the IP? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843357 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 ok i think i got it do i just do if($xmlObj->Countryname=="United States) {} to compare Edit:nope how do i compare the country from the IP? It will be more easier to compare with the country code rather than country name: if ( $xmlObj->CountryCode == 'US' ) { // DO YOUR STAFF HERE } Will it help? Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843364 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 now it is returning "this is not a united states IP adress" even though i am in the united states dunno where it is going wrong Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843367 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 now it is returning "this is not a united states IP adress" even though i am in the united states dunno where it is going wrong Please provide your code here, so that I can help you better. Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843377 Share on other sites More sharing options...
darkfreaks Posted May 27, 2009 Author Share Posted May 27, 2009 <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ return curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryCode; } } $location_data = get_ip_location($_SERVER[REMOTE_ADDR]); if ( $xmlObj->CountryCode == 'US' ) { echo "this is a united states ip";} else { echo "this is not a united states ip";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843380 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 Little BUG fixed in your code. Use this code snippet and test. <?php /** * Geolocation API access * * @param string $ip IP address to query * @param string $format output format of response * * @return string XML, JSON or CSV string */ function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ //return curl_exec($ch); $response = curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryCode; } } $location_data = get_ip_location($_SERVER[REMOTE_ADDR]); if ( $location_data == 'US' ) { echo "this is a united states ip";} else { echo "this is not a united states ip";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/159748-solved-ip-script-bugs-contd/#findComment-843389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.