-1

我为用户做了一个小的登录系统,他们可以在 account_setting 页面上登录并更改他们的用户信息。

但由于我对 php 很陌生,我想知道如何为每个用户提供自己的页面?公开的页面。

例如,用户“Steven”拥有user_id=17.

如何为该用户创建一个页面,以便在那里显示他的信息。像website.com/user=17……他的信息。

而且,如果页面可以充当模板,则只需根据用户的不同信息/网址。

我没有要求任何人为我写这篇文章,一个好的教程的链接就可以了:) 但是请不要在这个主题上发表 5 年的帖子。

4

4 回答 4

0

您需要userprofile.php?userid=17并使用$_GET['userid']根据该用户绘制信息。在 userprofile.php 上的 HTML 应该是相同的,只有数据会根据用户 ID 改变。如果未设置用户 ID,则显示错误消息或其他内容

于 2013-02-20T17:30:11.920 回答
0

一般说:

if (!empty($_GET['user']) && is_numeric($_GET['user'])){
  //Find him in database
  if (user_found($_GET['user'])){
    include "left_column.php" ;
    include "user_info.php" ;
  } else {
    echo "Page is not found" ; //or set header error 404
  }
} else {
  include "news_column.php" ;
}
于 2013-02-20T17:30:45.430 回答
0

website.com/index.php?user=17

<?php
require_once 'db/connect.php';

//Pull in 'user' from the query string.
$user = isset($_GET['user']) ? trim($_GET['user']) : null;

//Try to pull that user's info from the database.
$stmt = $dbh->prepare("SELECT * FROM user WHERE user_id = :user_id");
$stmt->bindParam(':user_id', $user);
$stmt->execute();
$user= $stmt->fetch(PDO::FETCH_ASSOC);

if(!is_array($user)){
    //User not found. Throw 404 or redirect.
    header('HTTP/1.0 404 Not Found');
    exit;
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo htmlentities($user['name'], ENT_QUOTES, "utf-8"); ?></title>
    </head>
    <body>
        <h1><?php echo htmlentities($user['name'], ENT_QUOTES, "utf-8"); ?></h1>
        <p>
            <?php echo nl2br(htmlentities($user['bio'], ENT_QUOTES, "utf-8")); ?>
        </p>
    </body>
</html>
于 2013-02-20T17:36:09.970 回答
-1

我将假设您将用户信息存储在数据库中。为了争论,我们会说它是一个 mysql 数据库。您需要做的是捕获用户 ID,然后从数据库中读取该列。

如果您的 URL 是 website.com/user/view.php?id=17,您的用户变量将在 $_GET['id']

所以是这样的:

$id = mysqli_real_escape_string($_GET['id']);
$results = mysqli->query("select * from users where id = '$id'");
$results = $results->fetch_assoc();

...将为用户显示信息;然后你只需构建一个页面来显示它。

于 2013-02-20T17:30:56.640 回答