mysql - How to grant access to certain users using PHP -
i having issue php, trying write program redirect user previous page (membersonly.php). here code isn't working me.
$sess = $_session['sess_username']; if ($sess == "admin") { return; } else { header("location: membersonly.php"); }
my attempt allow user "admin" admin.php page. code first thing run. $_session['sess_username'] variable assigned in login.php following code:
session_start(); $_session['sess_username'] = $_post['user']; header("location: membersonly.php");
now know correctly setting session username, because in page choose, can use echo $_session['sess_username']; , displays username. not sure doing wrong when try send user membersonly.php if username not admin. when try go page, denies access user, including admin.
[edit: solved] forgot add session_start(); @ top of page.
danbopes right, "returning" empty page. can this. note code not work unless username "admin" saved in session.
$sess = $_session['sess_username']; if($sess !== 'admin'){ header("location: membersonly.php"); exit(); } //admin content
Comments
Post a Comment