How to provide each registered user with their own URL using PHP?

I create a trading portal where each client will post their products, and we will provide a separate username and password for this client after the payment is made. Therefore, I need to create a URL link separately for each client so that it displays the products of this particular client.

For example, like Facebook, if I create a separate account, my page will be ( https://www.facebook.com/dinesh.darkknight ), where my own data or messages were shown. Thus, I need a separate page for each client on my site (www.seloncart.com/customername). As soon as I give the name of this customer, he should show the products posted only by this customer.

+4
source share
2 answers
  • Configure the server to run everything through a script (for example, in Apache, ScriptAlias / /hosts/example.com/htdocs/yourApplication.php )
  • Take a look at $_SERVER['PATH_INFO'] to determine which username (if any).
  • Use this information to decide if you want to display a โ€œproduct listโ€ or something else.
  • Search the database for relevant data

You will probably find that many MVC frameworks help quite a lot with steps 2 and 3.

+2
source

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); } } 

To translate into:

www.url.com/account/info/dinesh

You can also view the .htaccess file.

+1
source

Source: https://habr.com/ru/post/1482317/


All Articles