php - Admin user loses admin status -
okey, i'm working on site, , have 2 pages dont want every member see, , have tried add admin check them. problem can see 2 admin pages in menu when first logg in(as admin). if click them, throws me default page. , menu loaded default user.
here login, page arrays , page loadings:
$database = new databaseobject($host, $username, $password, $database); if(!isset($_session['user_id']) && $_post['login']){ $username = $database->clean($_post['username']); $password = $database->clean($_post['password']); $result = $database->query("select id, admin, username, password users username='$username' limit 1"); try{ if($database->num_rows($result) == 0){ throw new exception ('user not exist!'); } $user = $database->fetch($result); $user_type = $user['admin']; if(sha1($password) != $user['password']){ throw new exception('invalid password!'); echo "sha1($password)"; echo ".$user.['password']"; } $_session['user_id'] = $user['id']; } catch (exception $e){ echo $e->getmessage(); } } // if user logged in, load data , select page if(isset($_session['user_id'])) { require('user.php'); $player = new user($_session['user_id'], $database); $default_page = 'profile'; // check if user admin if($user_type == 1){ $pages = array( 'profile' => array( 'name' => 'profile', 'file' => 'profile.php', 'function' => 'profile', ), 'arena' => array( 'name' => 'battle arena', 'file' => 'arena.php', 'function' => 'arena', ), 'weapon_shop' => array( 'name' => 'weapon shop', 'file' => 'weaponshop.php', 'function' => 'weaponshop', ), 'alchemy_store' => array( 'name' => 'alchemy store', 'file' => 'healingshop.php', 'function' => 'healingshop', ), 'create_monster' => array( 'name' => 'create monster', 'file' => 'monsterpages.php', 'function' => 'createmonster', ), 'create_weapon' => array( 'name' => 'add new weapon', 'file' => 'weaponpages.php', 'function' => 'createweapon', ), ); } else{ $pages = array( 'profile' => array( 'name' => 'profile', 'file' => 'profile.php', 'function' => 'profile', ), 'arena' => array( 'name' => 'battle arena', 'file' => 'arena.php', 'function' => 'arena', ), 'weapon_shop' => array( 'name' => 'weapon shop', 'file' => 'weaponshop.php', 'function' => 'weaponshop', ), 'alchemy_store' => array( 'name' => 'alchemy store', 'file' => 'healingshop.php', 'function' => 'healingshop', ), ); } if(!empty($_get['page'])) { $page = strtolower(trim($_get['page'])); if(isset($pages[$page])) { require($pages[$page]['file']); echo "<p class='pagetitle'>" . $pages[$page]['name'] . "</p>"; $self_link = '?page=' . $page; $pages[$page]['function'](); } else { require($pages[$default_page]['file']); echo "<p class='pagetitle'>" . $pages[$default_page]['name'] . "</p>"; $self_link = '?page=' . $default_page; $pages[$default_page]['function'](); } } else { require($pages[$default_page]['file']); echo "<p class='pagetitle'>" . $pages[$default_page]['name'] . "</p>"; $self_link = '?page=' . $default_page; $pages[$default_page]['function'](); } }
and use fill menu links:
<div id='menu'> <ul> <?php foreach($pages $id => $page){ echo "<li><a href='?page={$id}'>" . $page['name'] . "</a></li>"; } ?> </ul> </div>
any solve appreciated! time , reading.
Comments
Post a Comment