Identifying User types
Posted 03 September 2006 - 05:04 PM
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
//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.
Posted 03 September 2006 - 05:07 PM
== 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
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community
Posted 03 September 2006 - 05:47 PM
Thanks for the help. Made the correct modifications and it all works perfectly.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users