User login site with his name on link

Asked

Viewed 104 times

0

I have a web system in PHP and MYSQL that has user registration. Users register and access the system, being redirected to a panel: nomedosite.com/panel.

What I need is that for every user who registers on the system, it can access your dashboard more intuitively. For example, João Yoko signed up and created the user name as yokojoao. So he could access his dashboard via the url: nomedosite.com/yokojoao. And each user in that way.

I have never created anything related. If anyone can help me.

  • This you can do in two ways. One of them is to use files. htaccess to redirect each user to a specific link according to the parameter. The other way is to use . htaccess to identify the whole parameter after the / as a $_GET and then in your application you get the value of his Dice that would turn something $_GET['yokojoao']

1 answer

2


PHP Developer, One way to do this you want is to use Friendly Urls like the mod_rewrite apache, capture requests and pass them to a file, as most PHP frameworks do today.

So when a user accesses for example nomedosite.com/yokojoao he’ll be accessing nomedosite.com/index.php passing by 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 the nomedosite.com/ would be sent as parameter for the script.

If you are using Apache and it is with active mod_rewrite you should have at the root of the site a file called .htaccess, yes . htaccess, with nothing before the point and no extension after 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 Rewritecond inform that conditions trigger the rules below, below there are two rules, I put a search to show how you could continue with a few pages after the / , if this rule did not exist the /busca would be understood as a username.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.