Connecting Tech Pros Worldwide Help | Site Map

Login page according to the access rights

Familiar Sight
 
Join Date: Jan 2008
Posts: 198
#1: Oct 2 '09
In my web site I want to load some menus without login and there is a admin login. When admin logged in I want to some more menus. This is my code. But it is not working. It display all menus every time. Please help me.
Expand|Select|Wrap|Line Numbers
  1. $page = $_GET['page'];
  2.  
  3. if ($page);
  4. else 
  5. $page = "index.php"; 
  6.  
  7.  
  8.     if($login=="True"){
  9.     //echo "inside admin login";
  10.         $array = array('Home'=>'index.php','Stock'=>'stock.php','Order Now'=>'orderNow.php','Contact Us'=>'contectUs.php','Add'=>'addVehicle.php','Edit'=>'editVehicle.php','Logout'=>'logout.php');
  11.  
  12.  
  13.     foreach ($array as $k=>$v){
  14.         if ($page == $v)
  15.             $background = "background='images/btn_inactive.gif' ";
  16.         else
  17.             $background = "background='images/btn_active.gif'";
  18.  
  19.         echo "<td width=200 height =35 align=center cellpadding=5 $background ><a href='$v?page=$v' class=toppanel >&nbsp;&nbsp;&nbsp;$k </a></td>";
  20.  
  21.         }
  22.  
  23.     }
  24.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#2: Oct 2 '09

re: Login page according to the access rights


how do you determine whether an admin or an user is logged in?
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#3: Oct 2 '09

re: Login page according to the access rights


It looks like your line 8 that is failing if it shows all the items.
Instead of checking if login is true, which you should also check if the type is the same like this:
Expand|Select|Wrap|Line Numbers
  1. if ($login===TRUE) {
You could also check if a certain variable isset() or if a $_SESSION value (which I presume is how you know they're logged in) is set?
Familiar Sight
 
Join Date: Jan 2008
Posts: 198
#4: Oct 2 '09

re: Login page according to the access rights


In my login page I checked whether user logged in or he is a guest.Actually my site no need to have any user login. I want to do a login part only the admin to enter data.
This is my login page and I'll get the value "true" from here.
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['login'])){
  2.     $username=$_POST['username']; 
  3.     $password=$_POST['password'];
  4.     if((!username)||(!$password)){
  5.         $login_error = '<p class= "errormsg">Please enter all fields</p>';
  6.     }
  7.         $password_encrpt = md5(substr($password, 1, -1));
  8.         $sql = "SELECT * FROM user WHERE  Username='$username' AND Password ='$password_encrpt'"; 
  9.         $result=mysql_query($sql);
  10.         $row = mysql_fetch_array($result);
  11.         $count=mysql_num_rows($result);
  12.         if($count==1){
  13.             echo $_SESSION['Username_Ses'] =$row['Username'];
  14.             $_SESSION['login'] = "True";
  15.  
  16.  
  17.         }
  18.         else {
  19.             $ADDERROR = '<p class="errMsg" align="Center">Invalid Username or Password</p>';
  20.         }
  21.  
  22. }
  23.  
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#5: Oct 5 '09

re: Login page according to the access rights


In your original script you do not use $_SESSION['login'], you use $login, which does not exist.
Reply