社交网络 PHP/MySQL 结构
我想创建一个社交媒体网站。我现在只是在计划,我想首先通过用户名/密码组合登录用户,检查 mysql 数据库并查看它们是否存在。这很简单。但我要问的是,就像 Facebook 一样,对于“Bio”页面,您会添加“从 user_id = $user_id 的朋友中选择”之类的内容吗?那么我是否在整个页面上使用相同的 user_id 来选择评论、联系信息、朋友、图片、喜欢、不喜欢?这是正确的还是这种糟糕的应用程序结构?
I want to create a social media site. I'm just planning it out at the moment, i'm thinking first to log the user in by username/password combo, checking against a mysql db and seeing if they exist. Thats simple enough. But i'm asking is, like Facebook, for a "Bio" page, would you put stuff like "select from friends where user_id = $user_id", that sort of thing? So do i use the same user_id over the whole page for selecting comments, contact info, friends, pictures, likes, dislikes? Is this right or is this poor application structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你还有很长的路要走。
请不要误解这一点,但您似乎缺乏手动构建这样一个平台所需的技能。
如果您有能力构建一个社交网站,您就会对身份验证系统有深入的了解,但您似乎缺乏这一点。
我建议您使用专门为社交互动(例如 Facebook)构建的自定义开源框架。
这里有一些可以帮助您入门的
I think you ahve a long way to go.
Please dont take this the wrong way but you seem to lack the required skills to manually build such a platform.
If you had it in you to build a social network site you would understand authentications systems down to a tee, but you seem to lack that.
What i would suggest is that you use a custom open source framework specifically built for social interactions such as facebook.
Here a few to get you started
当您登录它们时,从数据库中获取他们的用户 ID(我假设您在用户表中拥有完整的用户 ID 以及用户名/密码)并将其存储在会话中。然后,您可以在站点的所有页面上使用它来进行查询。如果您要将其基于查询字符串或发布数据,人们可以轻松更改它。
这是一种非常标准的做事方式(根据我的经验)。
您还可以将整个用户对象存储在会话变量中,但是您必须担心如何使其保持最新。
When you log them in, get their userID from the database (I'm assuming you have an integral user id as well as their username/password in the user table) and store it in the session. You can then use that on all the pages in your site to do queries. If you were to base it on the query string or post data, people can easily change that.
This is a pretty standard way of doing things (in my experience).
You could also store a whole user object in a session variable, but then you'd have to worry about keeping it up-to-date.