Jump to content

Archived

This topic is now archived and is closed to further replies.

nickd_101

Identifying User types

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.