I am currently working on a website I am making from SCRATCH :) Anyhow users will be able to create accounts (login and register pages already done), and then they will be able to view there profile. Now the problem I am running into is each user needs there own permalink for there profile's URL. I do not know how to go about doing this though! :( All I can find is using Wordpress to do it for me, but I do not want that. I would like to go about doing this with only PHP and HTML/CSS. Please help me out, thank you! :)
UPDATE 1
Thank you for the relpys, I am still a little confused though. Now if I use a GET, will that actually save the file? How exactly do permalinks work (sorry very confused! :O )? Like when I create the permalink is that creating a new file as well with the code inside of it? If so what would I be writing for that?
UPDATE 2
Sorry I am specifying what I am really asking. When a user created a account, I want it to AUTO create them a permalink (which would be a new file right?), how would I go about doing that?
UPDATE 3
Ok, so I am basically thinking of the same thing. So when a user creates a account this is the code that is executed:
//Create Account Page
$inputquery = "INSERT INTO users username VALUES :username";
$datasend = $connection->prepare($inputquery);
$datasend->execute(array(':username'=>utf8_decode($username),)); //Inputs it into the database
$username = $_POST["username"]; //The username input, then lets say that the account was created with that
$userprofile = fopen($username . ".php", "w"); //Makes a file with the users info, a PHP function
$text = include ('base.php'); //Grabbing the base layout
fwrite($userprofile, $text); //Setting the base layout to the userprofile page
So once that is one the code will be in the file. Then when the page is loaded, that so called "base" code is still there, and then is replaced with the details of the user. That is my rough attempt at this, it should work! :) Thank You for all of your help! :D
You can use a GET request, which will be stored in the URL. You just access it with $_GET['user']
, and the url will be in the form my.site.on.the.net/user.php?user=3141
. This URL can be stored in bookmarks, put in a webpage, or whatever else and it will link to that user's profile.
This will not save the file by itself. You will need to store the user information somewhere outside your web root, then use the PHP file to access that info based on the ID. You don't want to store the entire webpage; just store the information that is unique to that user (On SO, that would be stuff like their About Me, reputation, badges, etc.)
EDIT: Simple example (note that it doesn't have any password protection or anything else to prevent any random stranger from accessing it)
user.php:
<?php
function getPoints(){
// get the number of points from your data source
}
function getName(){
// get the name from your data source
}
?>
<!DOCTYPE html>
<html>
<body>
<img src="logo.png" alt="logo" />
<h1>Hello, <?php echo getName();?>!</h1>
<p>You have <?php echo getPoints();?> points.</p>
</body>
</html>
In this example, the data source only needs to store the user's name and number of points. The single PHP file fills in the rest of the page. To create a new user account, you will need to add the data for the user to your data source.