• 0

[PHP] Login, Access Level = Company Name


Question

I am trying to figure out the best way to do this. I have 2 or more companies that will login with their username and password. This same table holds their company name. What are your suggestions on how to go about this? I am a beginner-intermediate with php. Any help appreciated.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I go to the site and login with my username and password. I want to create one page that all users access but will only show information specific to that user.

Link to comment
Share on other sites

  • 0
I go to the site and login with my username and password. I want to create one page that all users access but will only show information specific to that user.

***If this is about PHP this should be moved into the Web server side sub forum as well...If this is actually meant for C#/c++ languages.. then ignore my post***

I would probebly just use a Numeric value to use rather than a string. I dunno for something like this I would just use a number to base my access levels on.

assign in the table, users who you want certain access to a number.. say level 0 is minimal access 1 is higher, 2 is higher.. etc etc.

You would just query what their access level is, and display contents based on that returned value. Although depending how you have stuff up it may just be easier to check against company name instead... which ever you find will be better for you really...

If you even wanted to, in your PHP code create Constants that represent company name to access level.. for example

define("COMPANY_ONE","0");
define("COMPANY_TWO","1");

Then just do this

if( $user->getACL() == COMPANY_ONE)	//$user->getACL() returns access level from users table
{
   //Display company one stuff
}

Kinda just roughly spewing stuff out. I find it easier to compare against a numerical value than a long company string. Then i can just use constants so it makes it easier to read and understand I'm comparing against company_one. Also less prone to spelling mistakes too i suppose....

Rough sketch but im sure someone can spew it out in more detail.. and probably a better way as well.

Edited by bolerodan
Link to comment
Share on other sites

  • 0

you may need to join the tables (I just learned this myself).

One table holds all the company data, so everyone who logins will see what other people in the company have changed.

and the other table is a list of usernames, passwords, and company name. Simply match the tables with the company name, to display the information.

Or do it the long way, and store everything in rows, such as company name, username, password, company info etc etc.

$result = mysql_query("SELECT * FROM example WHERE company='$CompanyName'") or die(mysql_error());  

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 
echo $row['name']." - ".$row['age'];

OR

$result = mysql_query("SELECT * FROM example WHERE Username='$Login_username' & Password='$Login_Password") or die(mysql_error());  

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 
echo $row['name']." - ".$row['age'];

Link to comment
Share on other sites

  • 0

when you register them, put a user level (1,2)

when they log in, get it to display the info for that level.

Im not skilled with php so i cant demonstrate it.

Link to comment
Share on other sites

  • 0

You can insert at registry, not sure if you wanna do that, or update it manually from an admin panel:

$result = mysql_query("UPDATE ClientTable SET Level='2' WHERE Company='CompanyNameHere'") 
or die(mysql_error());

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.