-1

I made a small login system for users, they can log in and change their userinformation on the account_setting page.

But since im pretty new to php I wonder how can I give each user their own page? A page that is public.

Ex, User "Steven" has user_id=17.

How can I create a page for that user, so his information gets displayed there. Something like website.com/user=17 ... His information.

And also if the page could act as a template, just diffrent information/url depending on user.

Im not asking anyone to write this for me, a link to a good tutorial would work just fine :) But please, no 5year old posts on the topic.

samayo
  • 16,163
  • 12
  • 91
  • 106
Kiwo smith
  • 43
  • 2
  • 6
  • What's wrong with 5 year old posts, as long as they answer your question? Your question is very basic, and 10 years ago people were doing much much more complex things with PHP! – Tarandeep Gill Feb 20 '13 at 17:31
  • I should be more specific, I ment none-secure pages. Using mysql etc – Kiwo smith Feb 21 '13 at 03:17

4 Answers4

0

you need userprofile.php?userid=17 and use $_GET['userid'] to draw the information based on that user. HTML should be same on userprofile.php only data will change depending on the user id. If userid is not set then show an error message or something

GGio
  • 7,563
  • 11
  • 44
  • 81
0

Generally saying:

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" ;
}
sybear
  • 7,837
  • 1
  • 22
  • 38
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>
Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66
-1

I'm going to assume that you're storing your user information in a database. For the sake of argument, we'll say it's a mysql database. What you need to do is capture the userid and then read only that column from the database.

If your URL is website.com/user/view.php?id=17, your user variable will be in $_GET['id']

So something like this:

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

... will bring up the information for the user; then you just build a page to display it.

DiMono
  • 3,308
  • 2
  • 19
  • 40
  • DONT USE mysql_* functions they've been deprecated and dont teach others to use that functions instead use PDO or MySQLi – GGio Feb 20 '13 at 17:32
  • Fair; so I would replace mysql_query with mysqli->query, and mysql_fetch_assoc($results) with $results->fetch_assoc() - what would I replace mysql_real_escape_string with? Or does mysqli do this automatically? I'm looking to revise my answer to current standards. – DiMono Feb 20 '13 at 17:52
  • Thanks alot! Yeah im using a mysql db, queries with mysqli ofc. – Kiwo smith Feb 20 '13 at 21:53