Hi, All

I would like my user to click on My Account link, with the help of some PHP magic i would like to determine which access level a user has and direct them accordingly to the right my account page.

In total I have 3 types of users outlined below.

I have an Enum set for the user type in the database 0 = normal user and 1 gold user and 2 = admin.

Normal user and gold user has different my account, in each my account there are different option.

I have stored the account type in a session and also in a cookies but not exactly sure how I can direct a user to the right My Account page.

My attempt:

session_start();

if (!$_SESSION['uid']) { 
$msgToUser = '<br /><br /><font color="#FF0000">Logged in users can only view this</font>
<p><a href="register.php">Join Here</a></p>
<p><a href="login.php">login</a></p>';

include_once 'msgToUser.php'; 
  exit(); 
}else if ($_SESSION['type']='1')  {
	header("location: goldaccount.php?id=$uid"); 
}else if ($_SESSION['type']= '0')  {
	header("location: myacount.php"); 
}
?>

Hope I have explained it properly
Thanks in advance

Recommended Answers

line 11 and line 13: you are doing comparison so there should be double equal operators.

else if ($_SESSION['type']== 1){ //single = means you are assigning

Apart from that the code looks ok.

Hope this helps.

Jump to Post

All 3 Replies

line 11 and line 13: you are doing comparison so there should be double equal operators.

else if ($_SESSION['type']== 1){ //single = means you are assigning

Apart from that the code looks ok.

Hope this helps.

line 11 and line 13: you are doing comparison so there should be double equal operators.

else if ($_SESSION['type']== 1){ //single = means you are assigning

Apart from that the code looks ok.

Hope this helps.

The pages seem to be navigating to the right pages however the page does not appear i get
:Oops! This link appears to be broken.

without the above script active the page seems to load fine

The pages seem to be navigating to the right pages however the page does not appear i get
:Oops! This link appears to be broken.

without the above script active the page seems to load fine

Is this the entire code? If not, you need to define $uid.

header("location: goldaccount.php?id=$uid"); //$uid is uid stored in session I suppose...

Also, I wonder if the other pages are in the same directory as this page. If so, do you get an oopsy for 'myacount.php'?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.