PHP:用户id动态页面
嗨 我正在制作一个用户可以互相访问的网站。 因此,我需要制作动态页面,这样如果我去……
www.mypage.net/user.php?id=32
那么我最终会出现约翰·史密斯的个人资料,并显示他的个人资料。 如果我转到 id=54 那么,我自己的个人资料就会显示。 我只是想知道,我将如何继续这件事? 当用户登录时,我已经将用户 ID 存储在会话中,但是如何创建 url,使其看起来像 ?id=32 而不仅仅是 user.php ?
有没有好的教程可以解释这一点? 提前谢谢!
Hi
I am making a website where the users can visit eachother.
Therefore i need to make dynamic pages so that if i go to let's say...
www.mypage.net/user.php?id=32
Then i would end up on John Smiths profile, and show his profile.
And if i went to id=54 then, my own profile would be shown.
I was just wondering, how would i go forward on this?
I already have the user id stored in a session when the user logs in, but how do i create the url so it looks like ?id=32 and not onlye user.php ?
Is there any good tutorials explaining this?
Thx in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经感觉到你会得到很多反对票。那是因为,你没有表现出任何努力并询问可以在网上轻松找到的东西。
这是您想要的基本内容:
您已经可以看到,您需要阅读 $_GET,当然还有mysql 查询。
此外,这些类型的概念相关问题更适合程序员。您应该阅读SO 的常见问题解答。
I can already sense that you are gonna get lots of downvotes. That's because, you are not showing any effort and asking about stuff, that can be easily found on the net.
This is the basic of what you want:
You can already see, that you need to read about $_GET and of course about mysql querying.
Further more, these types of concept related questions are more fit to Programmers. You should read SO's faq.
通过 URL 查询传递的所有参数都存储在 php 中名为
$_GET
的全局数组中。因此,如果您在 PHP 代码中输入www.mypage.net/user.php?id=32
,您可以像这样访问该值。$_GET['id']
。例如,我在 $_GET 上找不到像样的教程,但你可以尝试一下,希望它能有所帮助
http://www.tutorialarena.com/php/php-get-tutorial.php
All parameters passed through the URL query are stored in a global array called
$_GET
in php. So if you go to let's saywww.mypage.net/user.php?id=32
in you PHP code, you can access that value like this.$_GET['id']
. e.gI can't find a decent tutorial on $_GET but you can try this, hopefully it helps
http://www.tutorialarena.com/php/php-get-tutorial.php
好吧,只需输入该 URL 即可。这是将参数传递给 PHP 脚本的通用方法。 URL 中指定的参数称为 GET 参数。在脚本本身中,您可以通过检查
$_GET['id']
来访问这些内容。 GET 参数具有以下方案:即参数由 & 符号分隔,并且方案“名称”始终等于“值”。您在 URL 中指定的名称将在
$_GET
数组中可用。另一种传递参数的方法是使用 POST。您通常在从表单提交数据时执行此操作,以便它们的值不会显示在 URL 中。
Well, just type in that URL. That's a general method to pass parameters to your PHP script. Parameters specified in the URL are called GET-parameters. In the script itself, you can access these by checking
$_GET['id']
. GET-parameters have the following scheme:I.e. parameters are seperated by an ampersand and have always the scheme "name" equals "value". The name you specifiy in the URL is then availble in the
$_GET
array.Another way of passing parameters is using POST. You do this generally when submitting data from Forms so that their values don't show up in URL.
如果您在 html 中使用查询字符串 ?id 放置链接(例如:www.mypage.net/user.php?id=32),则可以通过在 PHP 代码中使用 $_GET['id'] 获取 url 。
也许这个链接可以帮助php初学者
If you place a link in your html somewhere with the querystring ?id (like: www.mypage.net/user.php?id=32), you can get the url by using $_GET['id'] in your PHP code.
Maybe this link can help php for beginners