Question: Page, User access

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Question: Page, User access

Post by ol4pr0 »

Ok.. basicly this is what i want to do. Restrict page access. Also for each user a differant menu bar is been loaded up. Now i can i put that best. Using database ofcourse. An administrator has the option to asign pages, or menu items to the users.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

are you asking a question?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

i don't think anyone will do that for free :)

If you post some code we might help you out
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well yes , i am asking on how i could do that best.

I was thinking about using serialize. than look for array_key_exist but.. maybe there is a better way to do so.


I dont have a code yet. Cuase i am not about to write something dumb and than having to rewrite it again.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that is a pretty broad project for one thread... let's do things one at a time... what would you like to do first? Authentication? Database design?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well i already have the page access written. So thats not really the problem. Altho i does need some changes ofcourse.. after having the level access put in to all of it.
My problem kinda is how to set up the db up best. Meaning asigning which Menu Items to load up when a certen user logs in.


Thats why i was thinking of unserialize(key_array_exist), assigning MenuItems ids to User ids. than checking them with something like this.

Code: Select all

array_key_exists('name', $_COOKIE) ? $_COOKIE['name'] : 'Whatever';


page access looks like this at the moment.

Code: Select all

function authenticate($username, $password) {

		$dbc = new database( );
		$dbc->connect() or die( $dbc->getError() );
		global $db;
		$sql = mysql_query("SELECT * FROM users WHERE login='$username' AND active='1'");
		$data = mysql_fetch_array($sql); 
		$encrypted_password = $data['password']; 
		$unique_id = $data['unique_id'];
		$password = crypt($password, $encrypted_password); 
		if ($password == $encrypted_password)  { 
			$date=date("Y-m-d H:i:s");
			$dbc->setQuery("UPDATE users SET session='".$_COOKIE['PHPSESSID']."' ,lastlogin='$date' WHERE unique_id='$unique_id'");
			$result = $dbc->select("users", array('login'=>"ikk") );
				if ($result) {
					foreach ($result as $row) {
						$_SESSION = array("unique_id"=>$row->unique_id,
										  "level"=>$row->level,
										  "valid"=>"yes",
										  "user"=>$row->login);
					}
				}

		return 1;
		}else{ 
		return 0;		
		}   
	}
Post Reply