Turning sections of a page on and off in admin section

Posted on 2006-05-15
Last Modified: 2008-07-03
Hi there,
I have a property listings site that we have created, and want to know if the following is possible:

The site is made up of modules, which people can pick and choose, but we normally install the modules.  Is it possible for the client from the administration section to ´turn off´or ´turn on´sections of the site.
e.g. Newsletter Module, CRM Module, etc.     or on the main page we have a property search box and featured properties, which we have there with an include command, is it possible to turn if off by making a selection in the admin section.

Thanks for any and all help.

Question by:Karen Liddy
    LVL 16

    Expert Comment

    in a config file you can set SEARCH_ENABLED = 1, NEWSLETTER=0

    in the main page, that should show the module, you add if condition

    if (SEARCH_ENABLED) ShowSeach();
    if (NEWSLETTER) ShowNewsletter();

    i guess that would be the simplest way around it
    LVL 9

    Expert Comment

    sure, you can turn it off and on.
    by checking through some "flag" or "variable" you had set in database from your admin section.

    Other than that, you might want to add in "Access Control List", to control the rights for certain users when installing the modules. So, the section  is actually on or either off when particular user have or don't have rights to view the page.



    Author Comment

    by:Karen Liddy
    thanks for those quick responses.  I´m fairly new to php but once i do something once i´ve got it.
    how should i code a config file (assuming config.php?)


    or do i need more?

    and then in the page i want to be able to turn it on and off put the if statements near the top of the page.

    But also how can i let a user turn them on and off via a form? tick boxes for on and off? how to pass the variables to the config file i mean

    thanks a mill
    LVL 16

    Expert Comment

    well, being new to php will not make u do a bullet proof modules and stuff like than, i don't want to put you down or something, but maybe you want to use a ready made application (free open source) that have things done for you like mambo, typo3 and smarty

    still, you can do it your self in a simple way, here is an eg
    say you got an include file holding the following modules; search, newsletter, and votes. and in the main page, where you want to display the search block, you call the function drawSearch().

    now, we want to be able to control the weather this module is displayed or not, then, in the main page, i'd do something like thie

    <?=(seach_eabled)?drawSearch : '' ?>

    this line means, if seach is enabled, draw search block, if search is not enabled, display nothing!

    i hope hope you can make use of this.
    good luck

    Author Comment

    by:Karen Liddy
    Okay sorry let me refrase that last one, i'm fairly new to php but can modify any scipt or program to do what i want it to do, it's just that starting from scratch is more challenging.

    Thanks for the info.  Another question, would the following be feasable:
    a database table with :

    with a form in the admin section to enable/disable the different modules.

    and then use the if statement to show or not the include file.

    how do i make the if statement look up the values in the db table?

    again thanks for help.
    LVL 9

    Expert Comment

    sure you may keep those details in database as you wish.

    But one things you need to really aware of, which is when the table you create is empty or the table had being truncated.

    before you have your if .. else statement, you will have to query those data from your database table.
    only with the data in your "enable" field, you may check whether the section should be include for particular user.

    if let say your "enable" field in the table you created have either "1" or "2"
    1 - allow access to the user
    2 - disable the access to the user

    if($row["enable"] == 1){  //$row["enable"] , data query from your database
    } else if($row["enable"] == 2){

    *if you have more than 2 options in the "enable" field, suggest to use "switch .. case" loop for the checking

    hope this helps.


    LVL 16

    Expert Comment

    saving such cofic files (which to load and which not to) are better not saved in db, it will cause an uncessary overload to the server. simply add them to an XML file, or CSV and parse them, it is a major difference in performance. parsing XML files is now so easy using simpleXML in PHP5.

    i'd advice you to use <div id=ddd class=ddd><?=drawSearch()?></div>

    and within drawSearch() itself, do the validation

    e.g. drawSearch(){
       if (eabled){
         show search items
    LVL 16

    Expert Comment

    you can restrict users from accessing this config file by putting it in a directory not accessed by apache, or using apache handler to prevent access to that file
    LVL 1

    Accepted Solution

    Assuming you are using mysql as your database and you have this:

    Table: user - userID, username, blah....
    Table: modules - moduleID, module, blah....
    Table : usermodulelink - usermodulelinkID, userID, moduleID

    This database model is normalised and works on the basis that you create a user in the user table.  The field userID should be an autonumber so that a unique ID is created.

    You also create a series of modules in the module table.  Again the moduleID should be an autonumber, incase you ever end up with two modules with the same name (for whatever reason!).

    The final table is the link table that will tell you which user is allowed which module.  Entries in this table will comprise of the user's userID and the modules moduleID, if a user has access to more than one module, there should be an entry in this table for each module.

    In a final solution, you would code a small form to populate the tables for you so that you don't have to edit them by hand.

    Then your php code would go along these lines:

    // Function to connect to the database
    function connectDB() {
        $db = "database";
        $u = "username";
        $p = "password";
        $link = mysql_connect('localhost', $u, $p) or die ('Unable to connect to SQL Server.');
        mysql_select_db($db, $link) or die ('Unable to select database.');
        return $link;

    // Set the path to where you keep your module files that you include
    $path = "path/To/Module/Files";

    // Set the username we are dealing with (this could be obtained from a login page...)
    $username = "user";

    // Create a link to the mysql database
    $link = connectDB();

    // Construct a query to give you the required modules for a given username.
    $query = "SELECT module FROM modules, user, usermodulelink".
        " WHERE username = '$username'".
        " AND usermodulelink.userID = user.userID".
        " AND usermodulelink.moduleID = module.moduleID";

    // Run the query
    $result = mysql_query($query, $link);

    // If it worked...
    if ($result) {
        // If we returned at least one row....
        if (mysql_num_rows > 0) {

            // Go through each row and include the specified module.
            while ($row = mysql_fetch_assoc($result)) {
        } else {
            echo "Error - no modules found.";
    } else {
        echo "Error running query - ".(mysql_error($link));

    // Tidy up!

    Hope this helps,
    LVL 1

    Expert Comment

    Incase you copy and paste any of the code.. I made a slight mistake with the paths to the modules...

    include($path.$module.".php"); should read: include($path."/".$module.".php");

    LVL 1

    Expert Comment

    ...or the $path variable should include a trailing slash.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now