将 Geo Ip 放入数据库 问题 PHP

发布于 2024-11-02 03:44:11 字数 549 浏览 1 评论 0原文

嘿,我知道这个标题真的很糟糕......我不知道还能说什么。无论如何,我有一个网站,我想跟踪他们的 ip 和地理地址 ip,并从 CSS-Tricks 中找到了这个片段, http://css-tricks.com/snippets/php/get-geo-ip-information/ 我得到了这个工作,返回的是 Array ( [domain] => dslb-094-219-040-096.pools.arcor-ip.net [country] => DE - 德国 [state] = > 黑森州 [城镇] => 弗尔斯海姆)


我制作了一张表,想要剖析该数组,并将城市放入一个 mysql 行,将国家/地区放入另一行,将域放入另一行。谁能帮我制作一个 mysql 插入,将所有这些不同的数据插入到每个相应的 mysql 行中?

感谢您的帮助...我最近才开始学习 php,所以我仍然是一个初学者。

Hey, I know the title is really bad...I didn't know what else to say. Well anyways, I have a website that I want to track their ip and geo address ip, and found this snippet from CSS-Tricks, http://css-tricks.com/snippets/php/get-geo-ip-information/
I got that working, and the return was Array ( [domain] => dslb-094-219-040-096.pools.arcor-ip.net [country] => DE - Germany [state] => Hessen [town] => Fl�rsheim ).


I have made a table and want to disect that array and put city into one mysql row, country into another one, and domain into another one. Can anyone help me make a mysql insert that inserts all of these different datas into each corresponding mysql row?

Thanks for all help...I have just recently started learning php, so I am still quite of a beginner.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2024-11-09 03:44:11

由于 geoCheckIP 已经返回一个数组(了解更多),您可以这样做如下所示:

$geoData = geoCheckIP($ip);

您将读取每个值,如下所示:

$geoData["domain"]
$geoData["country"]
$geoData["state"]
$geoData["town"]

MySQL 插入类似于:

$query = sprintf("INSERT INTO `users_data` (`domain`, `country`, `state`, `town`) VALUES ('%s', '%s', '%s', '%s')", mysql_real_escape_string($geoData["domain"]), mysql_real_escape_string($geoData["country"]), mysql_real_escape_string($geoData["state"]), mysql_real_escape_string($geoData["town"])); 

有关 mysql_real_escape_string 的更多信息

有关 php 和 mysql 的更多信息

Since the geoCheckIP already returns an array (read more), you can do as follow:

$geoData = geoCheckIP($ip);

And you would read each value like:

$geoData["domain"]
$geoData["country"]
$geoData["state"]
$geoData["town"]

And a MySQL insert for this would be something like:

$query = sprintf("INSERT INTO `users_data` (`domain`, `country`, `state`, `town`) VALUES ('%s', '%s', '%s', '%s')", mysql_real_escape_string($geoData["domain"]), mysql_real_escape_string($geoData["country"]), mysql_real_escape_string($geoData["state"]), mysql_real_escape_string($geoData["town"])); 

More on mysql_real_escape_string

More on php and mysql

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文