Jump to content

Identifying User types


nickd_101

Recommended Posts

Hi,
I was looking for help with distinguishing between user types on my website. I currently have a table in my MySQL database containing users, and within that table the "type" of user is identified (either agent or purchaser). I then proceed to initiate a session as  normal, extracting the type column for each user as they login using $_SESSION['type']. This seems to function ok, when i use an echo, the PHP prints the user type out and it seems to work.
However, i'm trying to restrict access to a page using an if statement so i have

if((@$_SESSION['auth']) && ($_SESSION['type']='agent'))
{
//Show page content
}
else
{
//Don't show content
}

However, when i do this, the page restriction does not work. I've experiment with variations on the above code, and had success initially, but the $_SESSION['type'] actually appears to change itself when i modify the code on some occasions, e.g. I managed to get functionality as required when i used ...['type']!='purchaser'

Any ideas as to the problem, or any suggestions as to an alternative method of distinguishing between member types.
Thanks
Nick
Link to comment
Share on other sites

use == in an if statement, not =

== is the sign for equality
= is the sign for 'assign' a value to something

so when you do $_SESSION['type']='agent', if the first part of your argument is true (the 'auth' part), then the whole thing will be true, even if 'type' is really a purchaser, because your statement with one = actually assigns 'agent' to the 'type' (overwriting the previous value), so it will always come out true.

other than that, you need to post some more code in order for us to see what else is going on
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.