Jump to content

Recommended Posts

if I had a page called..

settings.php

this had perhaps one setting for.. site display.

I mean.. the setting to display site to all users, or display a site to admins only and the rest see an under construction page for example.

 

How would I do it, handle it all etc?

Link to comment
https://forums.phpfreaks.com/topic/199313-website-settings-how-do-i-handle-them/
Share on other sites

sessions and access level.

$access=$_SESSION['access_level'];
if($acess>=2)
{$page=index.php;
  if($access>=9)$page2=admin.php;
}else
{$page=under_construction.php;}

or something like that depending on how your control is setup.

 

 

HTH

Teamatomic

sessions and access level.

$access=$_SESSION['access_level'];
if($acess>=2)
{$page=index.php;
  if($access>=9)$page2=admin.php;
}else
{$page=under_construction.php;}

or something like that depending on how your control is setup.

 

 

HTH

Teamatomic

I was thinking along the lines of.. classes?

include("settings.php");

class settings {
       public $status;

       public function sitestatus() {
               if($this->status == '1') {
                       header("location: error.php?csok=24131");
               }
      }
}

$settings = new settings();
$settings->status = $status; //gets this from settings.php
$settings->sitestatus();

Then I thought.. what if I had to extend settings..

I could call private functons within the public function. Though depending on the return of them.. some may return values, some may redirect, some may return nothing. That wont be possible to handle in just a public function?

Do not use

 

if ($accesLevel === 1)

 

This is annoying as anyone joining your project needs to create a "map" to match numbers to roles/groups instead use

 

if ($accessLevel === GROUP_ADMINISTRATOR)

 

Everyone knows in a blink that the if-body contains code specific for administrators while

 

if ($accessLevel === 5 || $accessLevel === 12)

 

Just keeps you guessing as to whom this applies. Some gave the argument that they were alone on the project and knew what numbers represent which roles. Well, try to go over this code again 6 months after you wrote this. Still remember? Make your maintenance work as easy as possible not harder, you just increase the chances of breaking your code.

 

In OOP terms there are many ways you can go, but your client most presumably wants to be able to add roles leaving you no option of hard-coding them. Zend_Acl gives you some great options in Access-Control.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.