如何创建会员“个人资料”在 PHP 中?
在 PHP 中创建会员资料的最佳方法是什么?例如,某些网站在地址栏中读取:profile.php?id=11233,然后读取profile.php?id=13563。这实际上是如何完成的?截至目前,我正在 MySQL 中保存此类类型的 URL,但是我将在哪里编写实际代码呢?我必须在 profile.php 中编写代码吗?或者我必须为每个 id 制作单独的文件?它是如何运作的?
What is the best way to create member profiles in PHP? For instance, some websites read in the address bar: profile.php?id=11233 and then profile.php?id=13563. How is this actually done? As of now, I am saving such types of URL's in MySQL, but where will I write the actual code? Will I have to write the code in profile.php? Or will I have to make separate files for each id? How does it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。访问者将访问
profile.php
,并且会有一个名为$_GET['id']
的默认变量集,其值位于 URL 中,例如11233
或13563
。然后,您可以在数据库中查询具有该 ID 的用户并显示正确的信息。If there is more than one variable, like
profile.php?id=123&type=cake
, then you will have two variables:$_GET['id'] = 123, $_GET['type'] = 'cake'
. It is stored in$_GET
because GET is the method used to access the page. Find out more at http://php.net/getThere is also another common method, called
POST
. This is used when forms are submitted withmethod=POST
. In that case, the information will be stored in the$_POST
array.Yes. Visitors will be visiting
profile.php
and there will be a default variable set named$_GET['id']
that has the value in the URL, like11233
or13563
. You can then query the database for the user with that id and display the proper information.If there is more than one variable, like
profile.php?id=123&type=cake
, then you will have two variables:$_GET['id'] = 123, $_GET['type'] = 'cake'
. It is stored in$_GET
because GET is the method used to access the page. Find out more at http://php.net/getThere is also another common method, called
POST
. This is used when forms are submitted withmethod=POST
. In that case, the information will be stored in the$_POST
array.是的,在这些示例 URL 中,数据库 ID 作为参数发送,由 PHP 解析。
基本步骤是
select * from profile where id=?
。当然,如何执行每个步骤的详细信息是问题的核心。我确信这里的人们会非常乐意回答有关如何连接和设置数据库以及如何在 PHP 中使用结果的问题。
一个简单的示例数据库将被设置为类似
Yes, in those example URLs, the database id is being sent as a parameter which would be parsed by PHP.
The basic steps would be
select * from profile where id=?
.The details of how to do each of those steps is the meat of the matter, of course. I'm sure folks around here would be more than happy to answer questions about how to connect to and set up a database, and use the results in PHP.
A simple example database would be set up something like