Marwan K. Elzeer
Marwan K. Elzeer

Reputation: 67

PHP - Creating a custom profile page

I have a website with a login & register form, I have also a myprofile.php webpage where I show the user his information, but, how can I let the website make an automatic webpage for every new user which is able to be shared. Such as:
www.siteurl.com/username
or
www.siteurl.com/user.php?id=1234567
that users can share with their friends or something like so?

I am using PDO.

Thanks!

Upvotes: 3

Views: 1647

Answers (1)

Obsidian Age
Obsidian Age

Reputation: 42304

To create a public profile page for each user in a database, all you need to do is pass the $_GET parameter into the query of your database:

$query = 'SELECT public_info FROM users WHERE id = ?';
$result = $dbc->prepare($query);
$id = $_GET['id'];
$result->bindParam(1, $id);
echo $result->queryString;

With the above query, $result will be dependent on whatever is passed in the id parameter of the URL. user.php?id=1 will output information for user 1, and user.php?id=2 will output information for user 2.

You can then use .htaccess to 'prettify' the $_GET parameter of the URL into whatever you'd like.

Hope this helps! :)

Upvotes: 1

Related Questions