John Davidson

php - If $_SESSION['uname'] not equal to "teacher", go back to main page

0 comments
Message:


I'm writing a page but I want to set it like only a member with "teacher" username can access to that page. There is a code like this I found:


<?php
session_start();
if(!isset($_SESSION['uname'])){

header('location:(main page url)');
exit;
}
?>

This code works for non-logged in users. But I also want it to work for non-teacher username users.


I'm kinda new to PHP, I know It's really easy to solve, but I really need an answer.


How to do it?


Thanks for your time.



My Answer:
'user'] is set, it means that the user is logged in and their information is stored in the session variable. This can be used to check if the user is authenticated and to retrieve their information when needed.

Rate this post

5 of 5 based on 5991 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us