How to use header redirect in an IF statement?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 14
Joined: Sun Oct 08, 2017 4:01 pm

Thu Mar 15, 2018 4:25 pm

What I want is. something like this... but I'm having trouble making it work.

It is at the very top of the page before any html or other output code...

Code: Select all

$user_type = $_SESSION['user_type'];
If ($user_type == "admin"){
	header('Location: admin_page.php'); 
} else{
	header('Location: user_page.php'); 
I'm using this in a user logon script and if redirects fine if I do not use an IF statement to decide where to redirect them.

I query the users table for the user_id and user_type and create a session variable for each of them to use through the session page to page.

But for some reason if I try to use the IF statement to control what page they get redirected to it no workie.

Thanks for any help.

php-forum Fan User
php-forum Fan User
Posts: 590
Joined: Fri Apr 01, 2016 2:18 am

Fri Mar 16, 2018 12:05 am

Code: Select all


Post Reply