User accessing site with name on link

0

I have a Web system in PHP and MYSQL that has a user registry. Users log in and access the system and are redirected to a panel: nomedosite.com/painel.

What I need is for every user who registers on the system, he can access his panel more intuitively. For example, John Yoko signed up and created the username as yokojoao. So he could access his panel via url: nomedosite.com/yokojoao. And every user that way.

I've never created something related. If anyone can help me.

    
asked by anonymous 23.02.2016 / 14:04

1 answer

2

PHP Developer, One way to do this is to use Friendly URLs like mod_rewrite of apache, capture requests and pass them to a file, as most frameworks in PHP do today.

So when a user accesses for example nomedosite.com/yokojoao he will be accessing nomedosite.com/index.php passing yokojoao as a parameter, which your PHP script can handle to identify the user.

Remember that in this URL scheme everything that is passed after nomedosite.com/ would be sent as a parameter to the script.

If you are using Apache and it has mod_rewrite active you should have a file named .htaccess at the root of the site, yes .htaccess, with nothing before the point and no extension after the access.

The contents of the file can be something like:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^busca/(.*)$ ./buscar.php?query=$1 
RewriteRule ^/(\d+)*$ ./login.php?username=$1

In this case the two RewriteConds inform you that conditions trigger the rules below, below are two rules, I put a search to show how you could continue with a few pages after /, if this rule did not exist /busca would be understood as the username.

The above script redirects any nomedosite.com/usuario to /login.php by passing the username to $ _GET ['username'] and if someone searches for nomedosite.com/busca/algumacoisa it passes $ _GET ['query'] with value of something to ./buscar.php

    
23.02.2016 / 14:38