FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


User Authentication based Menu Panel





therimalaya
I'm working with an web application, I need to implement user authentication in which some menus are to be shown only when the users are logged in. The menu format is as follows, which is in a separate file menu.php and is included on those pages which need the menu panel.


Code:
<?php
function menuBar($page=NULL)
{
    switch($page)
    {
        case 'CN55Req':
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/HomeDark.png' alt='Home'></a></li>
              <li><a href='entryForm.php'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php' class='selected'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
        break;
        case 'CN56req':
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/HomeDark.png' alt='Home'></a></li>       
                        <li><a href='entryForm.php'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php' class='selected'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
        break;
        case 'index':
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/HomeDark.png' alt='Home'></a></li>       
                        <li><a href='entryForm.php'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
        break;
        case 'entryForm':
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/Home.png' alt='Home'></a></li>       
                        <li><a href='entryForm.php' class='selected'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
        break;
        case 'fetchRecord':
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/Home.png' alt='Home'></a></li>       
                        <li><a href='entryForm.php'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php' class='selected'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
      break;
        default:
      echo("
      <div id='nav'>
          <ul>
              <li><a href='index.php'><img src='images/Home.png' alt='Home'></a></li>       
                        <li><a href='entryForm.php'>Record Entry</a></li>
              <li><span class='navslash'>/</span><a href='fetchRecord.php'>Fetch Record</a></li>
              <li><span class='navslash'>/</span><a href='CN55Request.php'>CN 55 Report</a></li>
              <li><span class='navslash'>/</span><a href='CN56Request.php'>CN 56 Report</a></li>
          </ul>
      </div>
      ");
    }
}
?>

The index can be shown for all user while the other should be shown to those who are logged in. I can not figure out, how to do this job..
Please help me..
sonam
This what you have is classic switch/case. You need to set $page. In most situation this is $_GET reading from url. But this is not secure if you are need login option. For your situation you need first to check login and then set $page in some way (my suggestion is session) and then on top of this script get session variable in $page. For example:

if is login OK define session
Code:
$_SESSION['page'] = 'CN55Req';



on the top of your script rewrite session in page variable

Code:
<?php
$page = $_SESSION['page'];
..... //rest of script



Sonam
Related topics
Forum
Windows to Linux ( Vice Versa )
[COMMUNITY PROJECT]Frihost Forum
Secure website with password?
Simple login system
User Authentication
Site Members' System
A very good PHP MySQL Tutorial
Unhide Your Administrator Icon
what is better? Sessions or Cookies
WHat is the best PHP guidebook?
PHP Image Questions
Windows XP SP3 comming soon
Authentication Module
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.