Redirect user according to login name

Asked

Viewed 1,264 times

-3

I’m trying to put a login system, where whoever accesses your login will have access to a different page. I am using php and mysql, but I am very beginner in the subject. I wanted the system to work like this:

login: password:

The person would be referred to a specific page

login:daniel password:daniel

The person would be forwarded to another page


Well, I must have left the question somewhat incoplete and so I came here to complete it:

I tried to create a registration system and a login, where the login he will forward you to a page that in case will be "www.site.com.br/user"

the codes in the folder below:

http://pastebin.com/VtgMfFhQ

  • What have you tried? Add the code to the question by clicking [Edit]

  • Voce can add one more column in your database containing the page to which the user will be directed. So, after validating the Voce user you would use the header("Location: xxxxx") function to direct the user to the corresponding page

3 answers

1

There is no code published I will say a generic:

<?

if($lucas){
header('location: https://example.com/lucas');
}

if($daniel){
header('location: https://example.com/daniel');
}

?>

Remarks:

You can also do the following, for all users:

header('location: https://example.com/'.$nome); 
//terá o mesmo resultado neste caso

Note:

If you use editors like Dreamweaver you need to turn BOM off when saving the file, this can be done in Unicode Options and uncheck, when saving, otherwise a result will be sent before redirecting which may cause error. In addition, obviously have no spaces before <?php or any other echo before the header.

  • The question is not clear, has no way to exemplify, but generates a bad answer or too wide (and turns tutorial).

  • Yes. I answered only to give an idea of what could be done, how it could redirect, maybe that’s the question. There is no way to know how it is structured or how you want to redirect. Anyway, I tried to help, only.

  • So, don’t get me wrong, but a bad question generated a not so good answer. Your example doesn’t make much sense.

  • I don’t know what the project is. Usually when they want to redirect to a different page it’s based on the name or id. For example, you enter your account and your profile appears, so I gave the second example, which I believe is the most useful. If he gives more details I edit the answer (if the question is not removed). " I’m new" - I always visit but I answer little - on Stackoverflow, but I will avoid answering very comprehensive questions on future visits.

  • Your good will is commendable, but it is good sometimes the OP does not get an answer with a weak question, so that in the future, better elaborate the question do not think? Anyway, maybe what seems to be not good for me, useful for the OP, let’s wait for him to analyze his answer. :)

1

In the .htaccess enter this data:

AuthType Basic
AuthName "Dados"
AuthUserFile /home/host/public_html/<DIRETORIO>/.htpasswd
Require valid-user

Already in the .htpasswd just go to the site http://www.htaccesstools.com/htpasswd-generator/ to generate a login and password, which as an example we will use this:

administrador:$apr1$5tnojPc/$QVe0Hkbg4ymK8NJHdkCDk0

Login: admin Password: password

:)

0

If you want a way to access directories by entering a login and password without having to use a database and a login/registration page, I believe that with the .htpasswd work.

  • 2

    The ideal would be to show an example of htpasswd that redirects according to login

  • now how to create the client page: in case I created the user: test, then it will be forwarded to the site www.site.com.br/test, but the page I will create the html, will be test.html? and it has to be in the same folder as the index of the site? if so would work with the code fixes?

  • Each folder you create will refer to a client, so you can create a folder called Clients and each subfolder referring to each client in fact. Within each client folder would contain the . htaccess and . htpasswd together with an index.html where the data of each client can be modified

Browser other questions tagged

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