mysql - How to Restrict Members wont see admin_page.php using session -


i have registered sessions using array containing: username, password , role. don't want show administrator page whomever enters site member. how can restrict admin_home.php using session>

this code:

-> login_check.php

<?php session_start(); include('connect.php'); $name = $_post['name']; $password = $_post['password']; $role = $_post['member']; $sql = "select * login_register name = '$name' , password = '$password' , role = '$role'"; $retain = mysql_query($sql, $con); $count=mysql_num_rows($retain); $row=mysql_fetch_array($retain); if($count == 1){ $_session['user'] = array('name' => '$name', 'password' =>  '$password' , 'role' => '$member'); if ( $role == "admin"){ header("location:admin_home.php");} else  if ( $role == "member"){ header("location:member_home.php");}} else { echo  "<a href='index.php'>click here login   </a>";} ?> 

-> member_home.php

<?php session_start(); if (!isset($_session['user'])){ header('location:index.php'); } 

-> admin_home.php

<?php session_start(); if (!isset($_session['user'])) { header('location:index.php'); } ?> 

i don't want allow members, under circumstance enter admin_home.php

also mysql fields: id, username, password, role should change if changes made in database. please tell me how can implement that.

i have wasted 2 days on , can't figure out. please me.

thanks in advance.

change session name..try this

change in login_check.php

<?php if ( $role == "admin") {  $_session['adminuser']=$_post['name']; header("location:admin_home.php"); } else  if ( $role == "member") { header("location:member_home.php"); $_session['user']=$_post['name']; } 

?>

change in member_home.php

<?php session_start(); if (!isset($_session['user'])){ header('location:index.php'); } ?> 

change in admin_home.php

<?php session_start(); if (!isset($_session['adminuser'])) { header('location:index.php'); } ?> 

try this

$_session['name'] = $variab;// array variable print_r($_session['name'][0]); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -