成为会员后,PHP 链接到用户个人资料

发布于 2024-08-05 22:54:26 字数 379 浏览 5 评论 0原文

我已经编写了登录和注册脚本。用户可以登录他们的帐户编辑他们的详细信息等。详细信息存储在用户表中,该表具有与用户相关的许多不同的数据属性。

我想知道,我该如何做到这一点,以便他们可以查看他们的个人资料并显示他们输入的所有数据。例如,如果用户名为“bob”的人注册并更改了他的数据,他可以单击链接“查看个人资料”,然后他可以看到他的公共用户个人资料。我知道如何获取条目并显示数据,但我的问题是我不明白如何为其他人和/或他们自己可以看到的用户创建个人资料。我希望为每个用户动态创建这些页面。

另外,如果我有一个页面可以检索所有最近注册的会员,它可以链接到他们的个人资料页面。

这是跨网站非常常见的事情,我知道有些 CMS 已经像 drupal 一样这样做了,但我想自己编写一个小型的受控解决方案。谢谢!

I already have written a login and register script. The user can login to their account edit their details etc. The details are stored in a users table which has many different data properties related to the user.

I was wondering, how do I make it so they can view their profile and it shows all the data they input. For example, if somebody with username "bob" registered and changed his data, he can click a link "view profile" and he can see his public user profile. I know how to fetch entries and display the data but my problem is I don't understand how to make a profile for my users that can be seen by others and/or themselves. I want these pages to be dynamically created for each user.

Also, if I had a page that retrieved all the recently registered members, it could link to their profile pages.

It is a very common thing across websites and I know there are CMS's that already do this like drupal but I want to code a small controlled solution by myself. Thanks!

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

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

发布评论

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

评论(3

浅浅 2024-08-12 22:54:26

使您的页面为“profile.php”

1) 使用 Get String 将 id 传递到该页面。链接为:....../profile.php?id=3
了解更多关于表单提交的Get和Post方法。 PHP 如何处理它 ($_POST & $_GET) google一下。

2) 在该页面“profile.php”中

 $id=isset($_GET['id'])?$_GET['id']:-1;
 settype($id , "int");
 if($id<1)
 {
     //wrong id, may be redirect
     header('Location : another-page.php');
     die();
 }
 // use this $id to get information from db and display the information

3) 如果您想动态地告诉该人他的个人资料链接是什么:
假设你有那个人的 $id :
$link = '...../profile.php?id=' 。 $id;

请考虑先学习基础的php。像 cookies、get、post、函数、数据库处理、会话、字符串处理、数组处理、全局变量。

Make your page 'profile.php'

1) Pass id to that page using Get String. Link would be : ....../profile.php?id=3
To learn more about Get and Post Method of form submission. And how PHP handles it ($_POST & $_GET) google it.

2) In that page 'profile.php'

 $id=isset($_GET['id'])?$_GET['id']:-1;
 settype($id , "int");
 if($id<1)
 {
     //wrong id, may be redirect
     header('Location : another-page.php');
     die();
 }
 // use this $id to get information from db and display the information

3) If you want to dynamically tell the person that what his profile link is:
Supposing you have $id of that person :
$link = '...../profile.php?id=' . $id;

Please consider learning basic php first. Like cookies, get, post, functions, db handling, sessions, string handling, array handling, global variables.

浪推晚风 2024-08-12 22:54:26

好吧,只需创建一个页面,例如 userprofile.php,它获取一个名为 id 的参数(我假设您的用户有 id ..否则有用户名)。如果不带参数调用该页面,该页面将使用当前会话用户作为配置文件 ID,并使所有字段可编辑,否则,如果传递“userprofile.php?id=123”,则它将显示其他成员的不可编辑版本。您还可以检查会话用户是否与请求配置文件的用户相同,在这种情况下,您也希望使页面可编辑。

Well, just create a page say userprofile.php that gets a parameter called id (I assume your users have id's .. otherwise have username). If the page is called with no parameter, the page will use the current session user as the profile id and will make all fields editable, otherwise, if it's passed with say "userprofile.php?id=123", then it will display a non-editable version for other members. You can also do a check to see if the session user is the same as the one whose profile is requested, in which case, you want to make the page editable as well.

〃安静 2024-08-12 22:54:26

您是否正在寻找类似的内容(已发布的内容和一些额外内容的合并):

 $SQL = "SELECT ID, First_Name, Last_Name, User_Name FROM Users" . 
        "WHERE ID = " . $_GET['id'];

 $con = mysql_connect('server', 'user', 'password');

 $db =  mysql_select_db('database_name', $con);

 $result = mysql_query($SQL);

 while ($db_field = mysql_fetch_assoc($result)) {
      print "User ID: " . $db_field['ID'] . "<BR>";
      print "User Name: " . $db_field['User_Name'] . "<BR>";
      print "First Name: " . $db_field['First_Name'] . "<BR>";
      print "Last Name: " . $db_field['Last_Name'] . "<BR>";
 }

当您想要创建指向其用户页面的链接时,类似这样的内容:

 print "<a href=user_profile.php?ID=" . $db_field['ID'] . ">" . $db_field['User_name'] . "</a>";

这需要您从页面上的链接传递的 ID ,例如 http://servername/page/list.php?ID=123然后上面的代码在数据库中检索您想要的任何信息(通过 SELECT 语句)。然后你就可以按照你想要的方式排列信息。

Are you looking for something like this (an amalgamation of what has been posted and some extra stuff):

 $SQL = "SELECT ID, First_Name, Last_Name, User_Name FROM Users" . 
        "WHERE ID = " . $_GET['id'];

 $con = mysql_connect('server', 'user', 'password');

 $db =  mysql_select_db('database_name', $con);

 $result = mysql_query($SQL);

 while ($db_field = mysql_fetch_assoc($result)) {
      print "User ID: " . $db_field['ID'] . "<BR>";
      print "User Name: " . $db_field['User_Name'] . "<BR>";
      print "First Name: " . $db_field['First_Name'] . "<BR>";
      print "Last Name: " . $db_field['Last_Name'] . "<BR>";
 }

When you want to create a link to their user page, something like this:

 print "<a href=user_profile.php?ID=" . $db_field['ID'] . ">" . $db_field['User_name'] . "</a>";

This takes the ID you pass through from a link on a page, such as http://servername/page/list.php?ID=123 and then the above code retreives whatever information you want (via the SELECT statement) in the database. Then you just lay the information out however you want.

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