Submit in php to redirect to different pages?

0

Good morning, I have a problem. I am starting in php and what happens is that I divided my code into several files so as not to have everything jumbled up in a single file. I'm doing a login type entry however I have two options; one allows the login of the administrator and another of the user so I want to reuse the code that I have separately in a file called login:

<body>

<?php require 'vali.php' ?>
<?php require 'header.php' ?>                    <!--"require" pide la informacion de la direccion especificada-->

  <h1>LOGIN</h1>

  <form action="menu.php" method="post">
    <input type="text" name="nick" placeholder="Nick" onkeypress= "return sololetras(event)" onpaste= "return false">
    <input type="text" name="contrasena" placeholder="Contraseña">
    <input type="submit" value="Entrar">
  </form>

The problem now is that this form only redirects to "menu.php" which is the main administrator menu. What I want is that if in the index you select login as a user, send to the user's menu and if you select it as administrator, then send it to the administrator menu ... I was thinking about doing it with an if or something, but I do not know, or maybe what I'm asking is just ridiculous, I do not know; help please.

The code where I select if login as admin or user is:

<body>

  <h1>SISTEMA TEST</h1>

  <form class="" action="controlador/login.php" method="post">
    <input type="submit" value="Administrador">
  </form>

  <form action="controlador/login.php" method="post">
    <input type="submit" value="Usuario">
  </form>

</body>
    
asked by Martín Ronquillo 07.02.2018 в 16:59
source

1 answer

1

Martin, you're on the right track.

The correct thing in this type of scenario where you have two types of roles (user, admin) is to have a single type of login. And when you validate the credentials of the user or admin (which at the end of the day are one more record in the same table) validate the role you have.

Based on the role you decide if you redirect it to one screen or the other.

Do not forget to check the user's role all the time! With this you will prevent a "normal" user from having access to the screens of an "administrator" user.

I hope I helped you! Hug

    
answered by 07.02.2018 в 17:06