How to create a page that has different information for each type of user?

Asked

Viewed 157 times

5

is my first question here at the Stack overflow. Well, I would like to know how to structure a php page to display different information to different users, because I don’t want to have more than one page for each type of user.

For example, assuming you have two types of users, Administrator and Client, I would like for the administrator to display an information X and for the Client a information Y. Additional information: I have in Super Global $_SESSION the type of user.

Sincerely yours truly, Ericks Rodrigues.

  • 1

    Are you using any database? Which one ? Att, Tao Father.

  • I am using PDO to access a mysql database, I am already manipulating the information and already acquire the data.

1 answer

2


<?php if ($_SESSION['tipo_usuario'] == 1) { ?>
    <p>informação do usurário tipo 1</p>
<?php } else { ?>
    <p>exibe informações do usuário 2</p>
<?php } ?>

Or

if ($_SESSION['tipo_usuario'] == 1) {
    \\ exibe informações do usuário 1
} elseif ($_SESSION['tipo_usuario'] == 2) {
    \\ exibe informações do usuário 2
} else {
    \\ exibe informações comum a todos
}

If this is not what you want, add more information to your question.

  • hello marcusagm , I understand the question of if, however I would like a structure not only for one or two data, I would like to load almost completely different pages (as if they were two different pages in the same). would like the best way to use an html code for each condition.

  • If you want a single file to display the data, you will have to test whenever you need to display information that is restricted. If it is a lot of differentiated information, it does not have the pq to unify in a single file, it would only hinder maintenance.

  • actually do not need to be completely different, in my application just show some links to users type 1 and others to users type 2, the purpose of the question is to know how I can more appropriately use the Ifs to define which html will be executed, because the only way I know to insert html into php is by using echo.

  • I changed the answer the first way with the solution

  • Ok, did not know that could use this way , thank you marcusagm!

  • Nothing Ericks ;) then tries to improve a little your question is title, can be useful to other people. Puts something specific"

Show 1 more comment

Browser other questions tagged

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