使用 php 在页面上显示靠近某人的项目的最佳方式是什么
基本上,我想在页面上向人们显示本地事件。因此,如果您来自加利福尼亚州,您会拥有与来自佛罗里达州的人不同的东西。我将在项目的其余部分使用 php,因此 php 是必须的。
我更愿意获取数据而不必向用户询问其他信息。如果我必须询问其他信息,我会想要使用邮政编码,而不是将该邮政编码与他们的 IP 一起保存到数据库中,这样我就不必再次询问。
Basically, I want to display local events to people on a page. So if you were from California you would have different things than someone from Florida. I am going to be using php for the rest of the project so php is a must.
I would prefer to get the data without having to ask the user for additional information. IF I have to ask for additional information, I would want to use a zipcode than I would save that zipcode to a database with their ip so I didn't have to ask again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想 GEO IP 函数 将为您带来 90% 的收益一路走来,即使不是一路走来。
I would imagine the GEO IP functions would get you 90% of the way there, if not all the way.
您如何知道此人的位置?
例如,您不能通过 ISP,因为他们的 ISP 地址可能与用户处于不同的状态。
如果他们必须登录,那么您可以知道他们登录时在哪里,但如果他们正在旅行并住在其他地方,那么您的信息是错误的。
这将是第一个挑战。
根据您想要获得的细粒度,将决定您的数据库的外观。例如,当我走在街上时,如果我使用移动设备,您是否能够使用我的 GPS 数据来确定靠近我的无麸质餐厅?还是以城市或大都市区为基础?
您使用 GPS 数据吗?
您将如何获取本地事件来更新您的应用程序?
有大量的信息没有得到解答,无法真正给您一个好的答案。
How will you know the location of the person?
For example, you can't go by the ISP, as their ISP address may be in a different state than the user.
If they have to log in then you can know where they were when they logged in, but what if the are on a trip and so staying elsewhere, now your information is wrong.
That would be the first challenge.
Depending on how fine-grained you are trying to get will determine what your database looks like. For example, while I am going down a street, if I am using a mobile device, will you be able to use my GPS data to determine what gluten-free restaurant is close to me? Or is it based on a city or metropolitan area?
Are you using GPS data?
How will you get the local events to update your application?
There is a great deal of information left unanswered to be able to really give you a good answer.
您是否想猜测访客的位置?如果这就是您想要的,请参阅 PHP GeoIP 扩展 或 < a href="http://www.maxmind.com/app/php" rel="nofollow noreferrer">MaxMind GeoIP api。他们都使用相同的数据库并提供免费和付费数据库。
这种方法的一个问题是IP地址不能保证准确的位置。但这通常是一个很好的起点。您应该让访问者能够轻松地更正他们的位置。
可能更准确的方法是使用 HTML5 地理定位 API,但这是实验性的,仅在最新的浏览器中受支持。即使有浏览器支持,网站访问者也需要能够找到其位置的硬件或允许他们设置自己位置的插件。如果您选择这条路线,您应该根据 GeoIP 结果进行回退。
Are you trying to guess the visitor's location? If that is what you want, see the PHP GeoIP extension or MaxMind GeoIP api. They both use the same database and offer free and paid databases.
One problem with this method is that the IP address does not guarantee an accurate location. It is often a good starting point though. You should make it easy for the visitor to correct their location.
A potentially more accurate method is to use the HTML5 geolocation api, but this is experimental and only supported in the latest browsers. Even with browser support, the site visitor needs hardware capable of finding their location or a plugin that allows them to set their own location. If you go this route you should have a fall back based on the GeoIP result.
您可以像其他人提到的那样在地理定位数据库中查找他们的 IP 地址,正如每个人都指出的那样,这并不是万无一失的,但它应该在大多数情况下都有效。
您还可以使用 Firefox 的位置感知浏览,它再次并不是万无一失的——但当我使用它时,它确实准确地定位了我的房子。当然,这仅适用于 Firefox 3.0+ 用户,并且仅在他们单击“接受”按钮后才有效,因此显然并非没有问题。
无论您选择走哪条路,只要确保某处有覆盖即可!你的方法可能在 99% 的情况下有效,但如果我属于从未获得正确信息的那 1% 的人,那就真的很烦人了!
You could look up their IP address in a geolocation database like other people have mentioned, and as everyone has pointed out, it's not foolproof but it should work most of the time.
You could also take a look at using Firefox's location-aware browsing, which again isn't foolproof -- yet it does accurately pinpoint my very house when I use it. Of course, this would only work for Firefox 3.0+ users, and only after they click the "accept" button, so it's obviously not without issues.
Whichever way you choose to go, just make sure there's an override somewhere! Your method might work 99% of the time, but if I'm in the 1% of people who are never shown the right information, that'd be really really annoying!