Member Avatar for nova37
<?php

// initiate curl and set options
$ipin = '69.72.129.3';
$ch = curl_init();
$ver = 'v1/';
$method = 'ipinfo/';
$apikey = '100.hva7qa7893wzcsc3x8dk';  
$secret = 'uHZVvYK5';  
$timestamp = gmdate('U'); // 1200603038
// echo $timestamp;   
$sig = md5($apikey . $secret . $timestamp);
$service = 'http://api.quova.com/';
curl_setopt($ch, CURLOPT_URL, $service . $ver. $method. $ipin . '?apikey=' .
             $apikey . '&sig='.$sig . '&format=xml');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);

// close curl
curl_close($ch);

// return XML data
if ($headers['http_code'] != '200') {
   echo "An error has occurred accessing this IP";
  return false;
} else {
   //echo $data;
   return($data);
}

i have neustar code it return ip info in xml format
i want to extract the data and assign it to variables like $ip , $org , $isp etc

so please help am not much famailer with xml i try to simplexml_load_string() but no success

Recommended Answers

All 11 Replies

Hi,

I am busy on my school homework right now, but I will attempt to post a solution sometime this weekend if you don't get a response until that time.

Before making my promise a final one, can you please tell us how these information are used?

$method = 'ipinfo/';
$apikey = '100.hva7qa7893wzcsc3x8dk';
$secret = 'uHZVvYK5';

Does the site needs log in?
Do you need to validate?

those questions are really important, because cURL will not work or not allowed to access those info.

Another hint! Did you ever try to use cookiejar on your cURL to make it work?

Member Avatar for nova37

ya its API Key from quova.com , used to get ip information

well no need to worry about key its free i will get another :D but if i help it will be appreciated

Member Avatar for nova37

Hi,

I am busy on my school homework right now, but I will attempt to post a solution sometime this weekend if you don't get a response until that time.

Before making my promise a final one, can you please tell us how these information are used?

$method = 'ipinfo/';
$apikey = '100.hva7qa7893wzcsc3x8dk';
$secret = 'uHZVvYK5';

Does the site needs log in?
Do you need to validate?

those questions are really important, because cURL will not work or not allowed to access those info.

Another hint! Did you ever try to use cookiejar on your cURL to make it work?

hey when you will post the solution for me :) still waiting

hits ::
just copy above code
run it
its will display data if you see the source code its xml data which is returned from servers
so you have to just parse return xml data ($data) and assign them to separate variables like $ip,$isp,$org etc

hey when you will post the solution for me :) still waiting

hits ::
just copy above code
run it
its will display data if you see the source code its xml data which is returned from servers
so you have to just parse return xml data ($data) and assign them to separate variables like $ip,$isp,$org etc

Nobody here is going to do your work for you and you shouldn't be waiting on people to solve your issue.

Start off here and learn this class well:

http://php.net/manual/en/book.dom.php

Member Avatar for nova37

ya i think have to do myself :(

Member Avatar for nova37

Check for SimpleXML library: http://www.php.net/manual/en/simplexml.examples-basic.php
You can start with $data:

$a = new SimpleXMLElement($data);
print_r($a);

So you can display the array and display the elements. Bye :)

it display nothing already i tried to use other xml functions too but it display nothing as output in array.. i do not know why .... :(

here ix xml data which we got from api

<?xml version="1.0" encoding="UTF-8"?>
<ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<ip_address>69.72.129.3</ip_address>
<ip_type>Mapped</ip_type>
<Network>
<organization>fortressitx</organization>
<carrier>fortressitx</carrier>
<asn>25653</asn>
<connection_type>tx</connection_type>
<line_speed>high</line_speed>
<ip_routing_type>fixed</ip_routing_type>
<Domain>
<tld>net</tld>
<sld>cyberleo</sld>
</Domain>
</Network>
<Location>
<continent>north america</continent>
<latitude>40.83243</latitude>
<longitude>-74.13984</longitude>
<CountryData>
<country>united states</country>
<country_code>us</country_code>
<country_cf>99</country_cf>
</CountryData>
<region>mid atlantic</region>
<StateData>
<state>new jersey</state>
<state_code>nj</state_code>
<state_cf>95</state_cf>
</StateData>
<dma>501</dma>
<msa>35620</msa>
<CityData>
<city>clifton</city>
<postal_code>07014</postal_code>
<time_zone>-5</time_zone>
<area_code>973</area_code>
<city_cf>80</city_cf>
</CityData>
</Location>
</ipinfo>

<?php
$ip_info = new SimpleXMLElement($data);
echo $ip_info->ipinfo->ip_type;
?>

i try to extract the ipinfo from it but failed :(

You can set an url as first parameter:

<?php
$xml = new SimpleXMLElement('file.xml',false,true); # try also with $data
print_r($xml);
?>

As second paramenter you can set these constants: http://php.net/manual/en/libxml.constants.php
Third paramenter is needed to declare source (in first parameter) as a file and not data strings like something you get from file_get_contents(). Your output should be:

SimpleXMLElement Object
(
    [ip_address] => 69.72.129.3
    [ip_type] => Mapped
    [Network] => SimpleXMLElement Object
        (
            [organization] => fortressitx
            [carrier] => fortressitx
            [asn] => 25653
            [connection_type] => tx
            [line_speed] => high
            [ip_routing_type] => fixed
            [Domain] => SimpleXMLElement Object
                (
                    [tld] => net
                    [sld] => cyberleo
                )

        )

    [Location] => SimpleXMLElement Object
        (
            [continent] => north america
            [latitude] => 40.83243
            [longitude] => -74.13984
            [CountryData] => SimpleXMLElement Object
                (
                    [country] => united states
                    [country_code] => us
                    [country_cf] => 99
                )

            [region] => mid atlantic
            [StateData] => SimpleXMLElement Object
                (
                    [state] => new jersey
                    [state_code] => nj
                    [state_cf] => 95
                )

            [dma] => 501
            [msa] => 35620
            [CityData] => SimpleXMLElement Object
                (
                    [city] => clifton
                    [postal_code] => 07014
                    [time_zone] => -5
                    [area_code] => 973
                    [city_cf] => 80
                )

        )

)

bye.

Member Avatar for nova37

You can set an url as first parameter:

<?php
$xml = new SimpleXMLElement('file.xml',false,true); # try also with $data
print_r($xml);
?>

As second paramenter you can set these constants: http://php.net/manual/en/libxml.constants.php
Third paramenter is needed to declare source (in first parameter) as a file and not data strings like something you get from file_get_contents(). Your output should be:

SimpleXMLElement Object
(
    [ip_address] => 69.72.129.3
    [ip_type] => Mapped
    [Network] => SimpleXMLElement Object
        (
            [organization] => fortressitx
            [carrier] => fortressitx
            [asn] => 25653
            [connection_type] => tx
            [line_speed] => high
            [ip_routing_type] => fixed
            [Domain] => SimpleXMLElement Object
                (
                    [tld] => net
                    [sld] => cyberleo
                )

        )

    [Location] => SimpleXMLElement Object
        (
            [continent] => north america
            [latitude] => 40.83243
            [longitude] => -74.13984
            [CountryData] => SimpleXMLElement Object
                (
                    [country] => united states
                    [country_code] => us
                    [country_cf] => 99
                )

            [region] => mid atlantic
            [StateData] => SimpleXMLElement Object
                (
                    [state] => new jersey
                    [state_code] => nj
                    [state_cf] => 95
                )

            [dma] => 501
            [msa] => 35620
            [CityData] => SimpleXMLElement Object
                (
                    [city] => clifton
                    [postal_code] => 07014
                    [time_zone] => -5
                    [area_code] => 973
                    [city_cf] => 80
                )

        )

)

bye.

try also with $data

cant work with $data :(

Member Avatar for nova37

well i did it ... problem solved :) .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.