Saturday 28 September 2013

json IP to db or file

json IP to db or file

First of all here is my code:
<html>
<head>
<title>the title</title>
<?php
$con=mysqli_connect("localhost","root","","test");
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("grandpaswine");
$query = "SELECT * FROM ips";
$result = mysql_query($query);
$dServer = array();
$rowNum = 0;
while($row = mysql_fetch_assoc($result)){
$dServer[] = $row['ip'];
$dServerC[] = $row['counter'];
$rowNum++;
}
?>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
var a = <?php echo json_encode($dServer); ?>;
var aC = <?php echo json_encode($dServerC); ?>;
var rowNum = <?php echo json_encode($rowNum)?>;
for (var i=0;i<rowNum;i++)
{ var city ;
var lon ;
var lat ;
var ip ;
var all;
var url = encodeURI('http://www.freegeoip.net/json/'+a[i]);
$.getJSON(url, function(jd) {
city = jd.city ;
lon = jd.longitude;
lat = jd.latitude;
ip = jd.ip;
console.log(city+ip);
document.write(city+ip)
});
}
});
</script>
</head>
<body>
</body>
</html>
So I have huge number of IP addresses and I use the www.freegeoip.net/json
to get the ip adresses details. In this code I write the result to the
console and to the page. And it works fine!
BUT
I would like to store the result to somewhere, for example: to file, to
database
How can I do this easily?

No comments:

Post a Comment