0

DB に、すべての管理者とその権限を格納するテーブルがあります。私は A ~ Z の文字で権利を設定しており、各文字は別のものにアクセスできます。問題は、アクセスできる場所を確認し、それらの領域へのリンクのみを表示したいということです。今のところ、これらすべての文字を for ループを使用していくつかの配列に配置し、メニュー出力をレンダリングするときに、アクセスできる項目のみをレンダリングするというアイデアを思いつきましたが、if (in_array(letter, rights))別の方法があるかどうかを知りたいです

4

1 に答える 1

1

私は自分のすべてのプロジェクトで使用する PHP クラスを作成しました。このクラスは、役割ごとに異なるアクセスを必要とします。クラスのコピーを貼り付けビンに入れました: class_role_restrictions.php

このクラスには、私が作成した別のクラスも必要です。これは、こちらから取得できます: better_mysqli.php

初期セットアップには、いくつかのデータベース テーブルの作成 (SQL create ステートメントは class_role_restrictions.php ファイルの最後のコメントにあります) と、管理インターフェイスを介したロール/ユーザー メンバーシップの追加が含まれます。

詳細な設定/使用法はここで取得できます: role_restrictions_detailed_example.php

セットアップが完了したら、次のように使用できます。

<?php

  include_once('class_role_restrictions.php');
  include_once('better_mysqli.php');


  $mysqli = new better_mysqli('your_server', 'your_user', 'your_pass', 'your_db_name');
  if (mysqli_connect_errno()) {
     error_log(sprintf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()));
     exit;
  }


  $role = new role_restrictions($mysqli, 'http://your_server.com/path/to/this/page/example.php');



  // == Restrict an entire page to authorized users only ==
    $role->restrict_to('role_name, to_restrict user_to', 'username_currently_logged_in');
  // .. now do stuff that only users in any of the roles listed are allowed to do

  // -- OR --

  // == Only do certain things if the username given is a member of any of the roles given ==
  if( $role->has_role('a_list, of_roles, allowed', 'username_currently_logged_in') ){
      // .. do stuff that only users in the given role(s) are allowed to do ..
  }


?>
于 2013-07-23T17:50:38.373 に答える