I'm making a website for my college where students, staff and the secretaries can log in. Each category of these people will go to the page named index.html
where they will be provided with a form with a username and password field. Now every category has a particular pattern of username; for eg the students have their ID number as their username, the staff have their names as username and the secretaries have their department as their username. When they enter the login credentials and submit, then they will be redirected to their particular pages. I've created 3 pages: student.html
, staff.html
and secretary.html
. And I want to redirect each of these to their respective pages. For eg if someone is a student, then he/she will be redirected to student.html
and so. Ofcourse I have to check the username before proceeding to know what among the 3 category the client belongs to, but I don't know the other part - the part of directing them to their particular pages based on the condition.
When someone is logging in, you already know which category he belongs to right?
So you should just redirect him to that category page. Something like this:
$redirect_to = $category . ".html"`; // decide which page i.e: 'staff.html'
header('Location: ' . $redirect_to); // redirect him to that page
See the php header documentation for more information.
If you can add a prefix to the ids would be easier to create the redirect logic.
After authenticating a user session and use header
to redirect e.g:
<?php
// you logic auth here...
/* this example assumes that the pages to be redirected are in the same
directory and defines three ids fictitious ($id) e.g:
students id: student-1231vjhj32v123h123gh
staffs id: staff-chuck-norris
secretaries id: secretary-office
*/
if(preg_match('/student/i', $id) ){
//redirect
header('Location: student.html');
}
if(preg_match('/staff/i', $id) ){
//redirect
header('Location: staff.html');
}
if(preg_match('/secretary/i', $id) ){
//redirect
header('Location: secretary.html');
}