Page for each user created in the database

0

My question quickly explained: I have a database with 20 registered users. Each user's page layout is already defined. Each user can only change their name, put their photo in an already defined field and tell a little about themselves. As soon as he logs in, how do I send him to your page? Example "pv.com.br/nomedousuario" Grato.

    
asked by anonymous 12.09.2018 / 00:56

1 answer

1

Basically this:

// ... lógica do login ...

header('Location: /'.$nomedousuario);
die();
  • Sanitize the data to make sure that $nomedousuário has no special characters. If so, you'll need to use something like this:

    header('Location: /'.urlencode($nomedousuario));
    die();
    
  • Always after using a redirection of this type, use die(); to ensure that nothing else on the page is processed and sent to the client. I've seen systems that served undue things for lack of this die() (the developer did not realize that he was sending confidential data, just because the redirect was taking place, but just turning off the redirect / em> to see the page)

  • Specifying the Location: header requested the complete URL, including protocol and domain name. Then there was an RFC "loosening" the requirement, but where possible, pass the full path (PHP has variables for it, in $_SERVER ).

12.09.2018 / 00:59