How do I give each registered user their own url using PHP?

I am creating a shopping portal where each customer will post their products and we will be providing a separate username and password for that customer once payment has been made. So I need to create an URL link separately for each customer so that it will show the products of that particular customer.

For example like Facebook if I create a separate account, my page becomes (https://www.facebook.com/dinesh.darkknight) where my own details or the posts has been shown. Like that, I need a separate page for each customer in my site (www.seloncart.com/customername). Once I give that customer name it should show the products posted by that customer alone.


Solution 1:

  1. Configure your server to run everything through the script (e.g., in Apache, ScriptAlias / /hosts/example.com/htdocs/yourApplication.php)
  2. Look at $_SERVER['PATH_INFO'] to determine what the user name is (if there is one).
  3. Use that information to decide if you are going to show a "list of products page" or something else
  4. Search your database for the appropriate data

You'll probably find that a lot of MVC frameworks help rather a lot with steps 2 and 3.

Solution 2:

If you use a framework like CodeIgniter, your URL works like this:

www.url.com/Controller/Function/Argument/Argument...

So in the code you might have:

class Account extends CI_Controller{
    public function info($username){
        echo getInfoPage($username);
    }
}

Which would translate to:

www.url.com/account/info/dinesh

You can also look into changing your .htaccess file.