RE: [PHP] Login form + User level access
At 8:07 PM + 6/29/10, Carlos Sura wrote: Thank you for your answer Ted, You are right, well, I do have my login form, but what I do not understand is how to implement switch statement. switch ($level){ case 0: include (admin.php); break; case 1: include (sales.php); break; case 2: include (superuser.php); break; } Try: case 0: header('location:admin.php'); exit(); break; Instead of includes. Now I'm wondering if every page has to have something like: if ($level==2){ } else { } Of course, you must check the level of permission granted to the user before allowing them to see any protected page. I would suggest using a $_SESSION['level'] during logon to set the level of permission and then on each protected page do something like this: $level = isset($_SESSION['level']) ? $_SESSION['level'] : null; if($level 2) { // redirect to somewhere else header('location:admin.php'); exit(); } // this will allow the super-user (level 2) to see everything while redirecting everyone else elsewhere Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Login form + User level access
At 7:46 PM + 6/29/10, Carlos Sura wrote: Hello everyone. I have this question: I'm developing a login system but what I need is to do is access levels I mean, in my database I have this users: Admin Superusers sales purchase etc So, What I do basically need is, when a user from sales log in.. I want him to see just the menu from SALES, He cannot see others menu options, and he can't get access, I was reading that I can do that with Switch, but really I have no idea about it... Any help? Thank you. Carlos Sura. Carlos: That's a little like saying, I want to build a car so I can drive around the country. I was reading that I could do that with a key, but I don't have any idea about it... Any help? Yes, you can use a switch statement, but that just one control structure in a much, much larger application. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Login form + User level access
Hello Carlos, Something like this (assuming that the field with the type of the user - admin, sales, etc. - is called `Status`, and the table is called `Users`): $f=mysql_fetch_assoc(mysql_query(SELECT `Status`, COUNT(*) AS `UserExists` FROM `Users` WHERE `Name`='.$_POST['name'].' AND `Password`='.md5($_POST['pass']).')); if ($f['UserExists']0) { // name and password are correct switch ($f['Status']) { case 'ADMIN': include adminmenu.php; break; case 'SALES': include salesmenu.php; break; // ... } } else { die (You entered either an incorrect login or an incorrect password.); } I assume you store crypted passwords in your database, and the algorythm is md5 (there are better solutions, but I used it simply for this example). -- With best regards from Ukraine, Andre Skype: Francophile; WlmMSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: m_elensule - Original message - From: Carlos Sura carlos_s...@hotmail.com To: php-general@lists.php.net php-general@lists.php.net Date: Tuesday, June 29, 2010, 10:46:14 PM Subject: [PHP] Login form + User level access Hello everyone. I have this question: I'm developing a login system but what I need is to do is access levels I mean, in my database I have this users: Admin Superusers sales purchase etc So, What I do basically need is, when a user from sales log in.. I want him to see just the menu from SALES, He cannot see others menu options, and he can't get access, I was reading that I can do that with Switch, but really I have no idea about it... Any help? Thank you. Carlos Sura. _ http://clk.atdmt.com/UKM/go/19780/direct/01/ Do you have a story that started on Hotmail? Tell us now -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Login form + User level access
Thank you for your answer Ted, You are right, well, I do have my login form, but what I do not understand is how to implement switch statement. switch ($level){ case 0: include (admin.php); break; case 1: include (sales.php); break; case 2: include (superuser.php); break; } Now I'm wondering if every page has to have something like: if ($level==2){ } else { } but, I think that might check link pages, and whole menu... Not, just the menu for admin as example. So, that's why I'm asking for help... I was saying just the idea to get example codes, to base on it, asking : how do I get to london?, not how do I drive a car? Thanks. Carlos Sura. Date: Tue, 29 Jun 2010 15:58:10 -0400 To: carlos_s...@hotmail.com; php-general@lists.php.net From: tedd.sperl...@gmail.com Subject: Re: [PHP] Login form + User level access At 7:46 PM + 6/29/10, Carlos Sura wrote: Hello everyone. I have this question: I'm developing a login system but what I need is to do is access levels I mean, in my database I have this users: Admin Superusers sales purchase etc So, What I do basically need is, when a user from sales log in.. I want him to see just the menu from SALES, He cannot see others menu options, and he can't get access, I was reading that I can do that with Switch, but really I have no idea about it... Any help? Thank you. Carlos Sura. Carlos: That's a little like saying, I want to build a car so I can drive around the country. I was reading that I could do that with a key, but I don't have any idea about it... Any help? Yes, you can use a switch statement, but that just one control structure in a much, much larger application. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com _ http://clk.atdmt.com/UKM/go/19780/direct/01/ Do you have a story that started on Hotmail? Tell us now